c

How to iterate through a fd_set

Hello. I'm wondering if there's an easy way to iterate through a fd_set? The reason I want to do this is to not having to loop through all connected sockets, since select() alters these fd_sets to only include the ones I'm interested about. I also know that using an implementation of a type that is not meant to be directly accessed is ge...

Compile time checking existance of stdint.h

I'm working with legacy embedded C code which defines the types uint8_t, uint16_t and uint32_t in a header file using the typedef keyword. For discussion, let us say the file typedefs.h contains these definitions. In my new C source module, I include stdint.h. I also include other header files which include typedefs.h somewhere in t...

SPOJ ADDREV Problem

Guys, got the answer in C ; THank you for all the help . Hey , I did go through the other threads on this(ADDREV Problem )(https://www.spoj.pl/problems/ADDREV/ ) but sadly, i am not able to get an answer by any of the three programs that i have written. ( in C , python and java ) . I am attaching the code snippets of all three. T...

Regarding the copying of objects

Possible Duplicate: Why does C++ support memberwise assignment of arrays within structs, but not generally? Why is it that we can assign the object of one structure to other directly eg: struct student s1,s2; s2=s1 //is perfectly ok. but we can not assign one array value to the other eg: int a[10],b[10]; a=b //is not all...

What is !0 in C?

I know that in C, for if statements and comparisons FALSE = 0 and anything else equals true. Hence, int j = 40 int k = !j k == 0 // this is true My question handles the opposite. What does !0 become? 1? int l = 0 int m = !l m == ? // what is m? ...

sem_wait not working as expected?

Follow up question to my pervious question: http://stackoverflow.com/questions/3579860/conditional-wait-with-pthreads I changed my code to use semaphores instead of mutex locks and conditional signals. However, I seem to have run in to a condition that I cannot explain. Here is the abstract function thread work { while (true) s...

Debugging Visual Studio 2010 DLL Project

I'm trying to debug a C/C++ native DLL project from Visual Studio 2010. I'm attempting to follow these instructions: http://msdn.microsoft.com/en-us/library/c91k1xcf(v=VS.100).aspx I want to use the built-in debugger and be able to step code, examine structures, etc. as I would do with a regular .exe project. The instructions on the pag...

Escaping "white space" escaping in C

I'm it really sure how to explain this question but i'll give it a try. I have this line of code in my program: scanf (" %c", &character); Notice the space before %c. This is supposed to keep the scanf from interpreting the last ENTER key as a character. This works, however after this line and its resulting printf output the program w...

How to change the working directory in C?

chdir can be used for constant character paths (it takes a const char *), but not for paths inputted by the user (since they have type char *). Is there any way around this? ...

Really simple error; I've probably forgotten a semicolon

I'm getting loads of errors like these: gfx.h:48: error: syntax error before 'buffer' gfx.h:48: warning: type defaults to 'int' in declaration of 'buffer' gfx.h:48: warning: data definition has no type or storage class gfx.h:73: error: syntax error before 'uint16_t' gfx.h:73: warning: no semicolon at end of struct or union gfx.h:74...

How to reimplement (or wrap) a syscall function in linux ?

Suppose I want to completely take over the open() system call, maybe to wrap the actual syscall and perform some logging. One way to do this is to use LD_PRELOAD to load a (user-made) shared object library that takes over the open() entry point. The user-made open() routine then obtain the pointer to the glibc function open() by dlsym()i...

Need some help with Android kernel

Hello guys, I am interested in Android kernel level programming. Actually I am a Linux kernel programmer. I would like to know how to start with the kernel and how compile, boot and about the Kernel level subsystems (EX: How file systems are implemented etc..) in Android. Any books or articles or a good guide to start are very much ap...

Optimizing SphereInFrustrum check

I have this SphereInFrustrum function here: 0.49% int FrustumG::sphereInFrustum(Vec3 &p, float radius) { int result = INSIDE; float distance; 2.40% for(int i=0; i < 6; i++) { 7.94% distance = pl[i].distance(p); 12.21% if (distance < -radius) 0.67% return OUTSIDE; 3.67% else if (distance < ...

How can I fix the cause of this compiler warning?

The following code is producing a warning when I compile it on 32-bit systems: 1087: warning: integer constant is too large for "long" type; how can I fix this so I don't get that warning and it works correctly on 32-bit? A valid input for this is: unsigned char str[] = "\x00\x17\x7c\x3a\x67\x4e\xcb\x01"; and the mypow function retur...

sigset: ignoring ctrl-c in Unix

Hello, I am trying to make my program ignore ctrl-c in unix which seems to work, the issue is that it keep writing "Syntax error". Here is the code extern "C" void ignore( int sig ) { fprintf( stderr, "\n"); // Print a new line // This function does nothing except ignore ctrl-c } int main() { // For ...

I can't make gcc work

I have to compile a .c file that came with a matlab toolbox. To this end I downloaded xcode 3.1.4, and now I am trying commands like gcc -o solvemc solvemc.c and getting errors like Undefined symbols: "_N_VFree", referenced from: _main in cca0ChgX.o _main in cca0ChgX.o _main in cca0ChgX.o _main in cca0ChgX....

Adding distant fog with OpenGL?

I', using GL_FOG, but it really only fogs up my geometry, I would like a way for the fog to feel like it encumbers an area, not just fog up my geometry, sort of like a box of fog... Is there a way to do this? Or possibly another way to give a smooth draw distance transition? Thanks ...

Making MSVC compiler GCC complient?

Is there a way to make the msvc compiler as strict as gcc? MSVC lets me do some pretty crazy things that result in hundreds of errors when I compile in linux. Thanks ...

How to compare pointer to strings in C

how to compare two strings in C? Help me, I am beginner@@ char *str1 = "hello"; char *str2 = "world"; //compare str1 and str2 ? ...

Help with this issue

Here is my issue. I'm rendering axis alligned cubes that are all the same size. I created an algorithm that rendered around the player like this: ****** ****** ***p** ****** ****** While this does work, the player does not see this whole radius. I know the player's rotation angle on the Y, so I was hoping to modify my algorithm based ...