c

C sendto returns -1 if broadcasting on a vpn

I have built a udp server that broadcasts a message every so often. It broadcasts without a problem. But if I turn on my vpn, then sendto will start returning -1 even though I am sending to INADDR_BROADCAST. I am running this on a mac btw if that changes anything. I really have no idea why this would happen, I am really wondering how ...

Emacs lisp question

Hi, I want this function to compile the contents of the current buffer(a C file) and show the output(a.out) if the compilation succeeded (defun c-shell-compile () (interactive) (save-buffer) (if (equal (shell-command (concat "gcc " (buffer-file-name))) "(Shell command succeeded with no output)") (shell-comman...

How to receive and decode SNMP traps in a C (or C++) application?

I am trying to write a very small SNMP trap receiver, listening to UDP port 162. Traps come in fine, but I can not decode them. I have found libber, but it can't decode the traps for some reason. I am probably using it wrong. I imagine decoding an SNMP trap should be fairly simple and that I am missing something crucial. Is it possibl...

When to use DBL_EPSILON/epsilon

The DBL_EPSILON/std::numeric_limits::epsilon will give me the smallest value that will make a difference when adding with one. I'm having trouble understanding how to apply this knowledge into something useful. The epsilon is much larger than the smallest value the computer can handle, so It would seem like a correct assumption that it...

C switch statement: has default to be the last case?

Consider the following switch statement: switch( value ) { case 1: return 1; default: value++; // fall-through case 2: return value * 2; } This code compiles, but is it valid (= defined behaviour) for C90/C99? I have never seen code where the default case is not the last case. EDIT: As Jon Cage and KillianDS wri...

Difference between const char* p and char const* p

Possible Duplicate: what is the difference between const int*, const int * const, int const * Are there any Difference between const char* p and char const* p ...

Reading/Writing Nibbles (without bit fields) in C/C++

Hello all, Is there an easy way to read/write a nibble in a byte without using bit fields? I'll always need to read both nibbles, but will need to write each nibble individually. Thanks! ...

C90 - C99: register struct

Hello is "register struct" legal? In terms of standards and (separated from standards) in Gcc? ...

Why does malloc(0) return valid memory address ? What's the use ?

Possible Duplicates: what does malloc(0) return ? whats the point in malloc(0)? Why does malloc(0) return valid memory address ? What's the use ? ...

Tips for reading and grasping the big picture of large C projects?

Possible Duplicate: Good techniques for understanding someone elses code I am going through the source code of this old game (MMO): http://www.brockhaus.org/merc2.html and I can read C and understand it, however the problem I have is figuring out where everything starts and stops, and is coupled together. It's all these code a...

Educational example to show that sometimes printf as debugging may hide a bug

Hello all, I remember when I was in some course of C programming, a teacher once suggested to use printf to watch the execution of a program that I was trying to debug. This program had a segmentation fault with a cause that I cannot remember at the moment. I followed his advice and the segmentation fault disappeared. Fortunately, a cle...

Which of * and [] bind strongest in C?

Possible Duplicate: C pointer to array/array of pointers disambiguation In C, is int *thing[5] an array of five pointers, each pointing to an integer, or a pointer to an array of five integers? ...

Memory leak using GtkAnimView

In my C GTK+ application I must load and display images using a GtkAnimView widget. I have a loading function: void loading(GtkWidget *widget, const char* file_path, MainWin* mw) { GError* error; gssize n_read; gboolean res; guchar buffer[LOAD_BUFFER_SIZE]; GInputStream* input_stream; GFile *file = g_fil...

Find width of a tab item? (WinAPI)

I want to be able to know how much room a particular tab takes up, is there a way to calculate this knowing it's text and having its item struct? Thanks ...

GCC can't locate headers even when the search directory is correct

Once again, GCC is making me feel like an idiot for having trouble with the simplest things. I've included a header: #include "PDL.h" Then, I try to compile: arm-none-linux-gnueabi-gcc -I/cygdrive/c/PalmPDK/include -I../lua-5.1.4/lua-webos/include -O2 -Wall -shared -nostdlib -mcpu=arm1136jf-s -mfpu=vfp -mfloat-abi=softfp -lpdl But ...

Linking problem using OpenMp with ctypes.

Hi there, I have a c99 function that uses openmp, which works as expected. I also wrote a ptyhon interface using ctypes which causes the problem. Ctypes/python can not find the library for openmp. Here is the error massage: File "foo.py", line 2, in <module> foobar=cdll.LoadLibrary("./libfoo.so") File "/usr/lib/python2.6/ctypes/_...

How many passes over the code does gcc use?

Specifically for C and C++, how many passes are used by default? Does this number change depending on the level of optimization used? (it should) Can it be changed directly? I was searching for this information in http://gcc.gnu.org/, but googling using site:http://gcc.gnu.org/ did not yield anything. Any pointers to any documentati...

How do I get the MAC/Serial of a DVB device on Linux?

I have a couple of Hauppage 950Q USB tuners attached to a Linux PC (CentOS) and I want to be able to differntiate which one is which. On windows I can query the MAC of the USB tuners to accomplish this, but on Linux I am not sure how to do that because this functionality is not exposed (to my knowlege) by the video4linux API that I'm ac...

member alignment in c struct-embedded union

Hi I am modifying a bit of C code, that goes roughly like this: typedef struct STRUCT_FOO { ULONG FooInfo; union { ULONG LongData; USHORT ShortData; UCHAR CharData; }; } FOO; ... FOO foo; ULONG dataLength = offsetof(FOO, CharData) + sizeof(foo.CharData); Obviously, the code tries to figure o...

About associativity in 'C'

How can i decide or understand whether any statement or expression has left to right or right to left associativity? ...