Are most compilers able to check if an addition operation that was performed earlier in the code resulted in a carry?
For example:
unsigned int n = 0xFFFFFFFF; // 8 F's
// doing some stuff here ...
n = n + 1;
// doing some stuff here, without changing the value of @var n
if (n > UINT_MAX) {
// n has a carry
}
...
I am trying to implement binary search tree operations and got stuck at deletion.
11
/ \
10 14
Using inorder traversal as representation of tree initially output is 10 11 14.
Deleting node 10, output expected is 11 14 but I am getting 0 11 14.
Deleting node 14, output expected is just 11 but I am getting 0 11 67837.
Please ex...
Does anyone know if the source code for Objective-C is still available from when it was just a pre-processor? Would be curious to see how it was implemented back then.
Thanks.
...
Im playing with 'recvfrom' and 'sendto' calls using UDP.
I have a client that just broadcast UDP packets on port 6000.
I have a server that binds a socket on port 6000, and do a single recvfrom.
The problem is that sin_port member of struct sockaddr returned from recvfrom is always incorrect. Why?
I would post some source code but some...
I have a daemon which gets started as root (so it can bind to low ports). After initialisation I'd very much like to have it drop root privileges for safety reasons.
Can anyone point me at a known correct piece of code in C which will do this?
I've read the man pages, I've looked at various implementations of this in different applicat...
I have a function that reads a rom file into memory and automatically allocates to fit the file but every time I try to read from the file descriptor, fread() returns zero. I'm unsure what I'm doing wrong. can anybody help?
int read_rom(const char *filename, unsigned char ***rom) {
int rom_size;
FILE *fd = NULL;
if((fd = fopen(file...
Hi.
I'm creating GTK+ application that has embedded Ruby interpreter, small logic functions w/o side effects (those who only return some values) are working ok already, but I would like Ruby scripts to interact with main programs widgets. I know there is ruby-gtk2 gem, but how do I tell Ruby that widget passed from C must be wrapped wit...
Hi all ...
I'm working on this project about how to develop authentication server that serves multiple clients at a time
the client gives the name and password as request and the server authenticates the request and returns the result ... ALL communications between client and server should use message queues techniques ...and i want it ...
How do I get the byte size of a multibyte-character string in Visual C? Is there a function or do I have to count the characters myself?
Or, more general, how do I get the right byte size of a TCHAR string?
Solution:
_tcslen(_T("TCHAR string")) * sizeof(TCHAR)
EDIT:
I was talking about null-terminated strings only.
...
Hi, I want to create a child window that takes up all the space of the left side of main window, but its minimum width is 128 pixels. I also want it to be resizable, but only on the right edge, and makes sure that the width stays at the minimum of 128. Creating the child window with these styles: WS_EX_STATICEDGE, WS_SIZEBOX|WS_CHILD|WS_...
I am looking for an interpreter for a stack-oriented programming language released under GPL or LGPL license, written in C or Objective-C.
...
Are there any C APIs for fetching free memory, swap memory consumption and to fetch file handle count similar to statvfs for file system information instead of directly parsing the /proc file system?
...
I have a window that creates a lot of other common controls such as menus, toolbars with buttons and combo boxes, and a status bar. The problem is that the window never receives a WM_KEYDOWN message whenever I press Enter or Esc, but I need to handle these. Is there any common control that is known to interrupt these keys?
...
I know this is platform-specific question, however, I would like to do some run-time analysis of an application to detect cache misses and hits. I know cachegrind, a tool for valgrind, and of vtune, and that a slew of other profiling utilities exist. However, I am interested, in implementing my own version of cache-miss detection. I k...
Hi,
I need to look up MAC address in the local network and I'm using Linux. What I do is send a ARP request with libnet, but after I send 3 requests, the cache still won't update. I use wireshark to catch the packets. From wireshark, I did get 3 ARP replays, after each of my ARP request. Does anyone know how come the ARP cache won't ...
I am thinking of buying the book 'The C Programming Language', aka the Bible of C. I read that it doesn't cover the additions to C99. Should it really matter? Or is there a better book out there that I can buy.
Note that I can program in C++ and Python, however I never touched C before but now I have decided to - so I am not a complete ...
I'm trying to compile the open source project Programmer Dvorak. The problem is that it's a bit old and doesn't build with the current versions of the build tools.
You can see the full source code with modifications I made online at my project's Google Code page. Revision 2 is the unmodified source files from the original project. Revis...
Hi.
I'm working on a program which uses shared memory. Multiple instances of said program will either connect to an existing one or create it anew, and give it back to OS when there are no other processes or just detach it and terminate. I thought of using a simple counter to keep track of how many processes use it.
I'm using atexit() ...
A couple of days ago I had to investigate a problem where my application was showing abnormally high CPU usage when it was (apparently) in idle state. I tracked the problem down to a loop which was meant to block on a recvfrom call while the socket had been set to O_NONBLOCK-ing resulting in a spin lock. There were two ways of solving th...
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int value;
struct node *next;
}LLIST;
LLIST *list_add(LLIST **p, int i)
{
if (p == NULL)
return NULL;
LLIST *first = malloc(sizeof(LLIST));
if (first == NULL)
return NULL;
first->value = *first;
*p = first;
first->value = i;
}
i...