c

Enforcing the ANSI C standard in Eclipse

Is there an option I can change in Eclipse to make sure that my code has got to be ANSI C-compliant before it can be compiled? ...

What does this short snippet of C code do

Could someone explain what this code does size = *(int *)data; // size of string plus header word off = (size + 3) & ~3; chan = *(int *)(data + off); data[size] = '\0'; // zero terminate I think it's got something to do with making the data a multiple of 4? ...

What's the real utility of make and ant?

While i'm developing in C/C++ and Java, i simply make a compile.bat script that does everything, that's fine for me. Why should i use make and why should i use ant? ...

sqlite3 close statement is not working

I'm using a C program with sqlite3. Some times insert works.But sometime ,its not working. assert(retval == SQLITE3_OK) gives error. while debugging I found retval value of sqlite3_step() is error code = 5 which refers to Database file is busy Even closing with sqlite3_close() return error code 5. Any thoughts on how to close the data...

Newbie C Array question over functions.

Hi all, I bought a C book called "The C (ANSI C) PROGRAMMING LANGUAGE" to try and teach myself, well C. Anyhow, the book includes a lot of examples and practices to follow across the chapters, which is nice. Anyhow, the code below is my answer to the books "count the longest line type of program", the authors are using a for-loop in th...

How to zero out new memory after realloc

What is the best way to zero out new memory after calling realloc while keeping the initially allocated memory intact? #include <stdlib.h> #include <assert.h> #include <string.h> #include <stdio.h> size_t COLORCOUNT = 4; typedef struct rgb_t { int r; int g; int b; } rgb_t; rgb_t** colors; void addColor(size_t i, int r, i...

Need to write to a string constant, how do I work around this?

I have the following code: int main() { char *sPPhrase[51]; /* Input */ printf("Enter string (max. 50 chars):\n"); fflush(stdout); /* Works around an annoying Eclipse bug that fails to display the output from the printf command */ scanf("%s", *sPPhrase); /* Won't work */ /* More code g...

Opinions on not using prototypes for static functions.

Does anyone have any opinions on not using prototypes unless necessary for functions declared "static". Do you always put them at the top of your translation unit? I tend to but recently I've been thinking about why not rely on the ordering of the functions and in way you can limit some scope of where the function can be called from, pot...

What to replace in this C Puzzle ?

Now this is a silly puzzle I got from some exam paper,sadly I am unable to figure it out from last 15 minutes. #include <stdio.h> int main(void){ /* <something> */ putchar(*(wer[1]+1)); return 0; } What should we replace in place of something in order to get the output e.Now we know putchar takes a int as argumen...

What is a good general approach for deciding return values in C?

My program is written in C for Linux, and has many functions with different patterns for return values: 1) one or two return n on success and -1 on failure. 2) some return 0 on success and -1 on failure. 3) some return 1 on success and 0 on failure (I generally spurn using a boolean type). 4) pointers return 0 on failure (I generally sp...

visual c++ 2008 express

Hi all, I need to compile several c++ projects using the version 6.0 compiler. Is there any way to compile my projects using the visual c++ 2008 express edition compiler. In java, there is a command to specify which version of the compiler to use on commandline, I was hoping that c++ 2008 has such a command as well. Kind regards. ...

calculate the degree between two triangles in ansi c cuda

hi wanted to calculate the degreee between two triangles where every point of them has a 3d coordinate.... i.e. triangle 1: point1(x1,y1,z1), point2(x2,y2,z2), point3(x3,y3,z3). triangle 2: point1(x1,y1,z1), point2(x2,y2,z2), point4(x4,y4,z4). yes, the triangles always share exactly same two points. is there a way to calculate the degr...

long long length question

I'm trying to implement George Marsaglia's Complementary Multiply-With-Carry algorithm in C. It seems to work great under Win7 64 bit and Linux 32 bit, but seems to behave strangely under Win 7 32 bit. The random number it returns is 32 bit, but there's a temporary value used internally that's supposed to be 64 bits, and it's declared: ...

opengl: glFlush() vs. glFinish()

I'm having trouble distinguishing the practical difference between calling glFlush() and glFinish(). The docs say that glFlush() and glFinish() will push all buffered operations to opengl so that one can be assured they will all be executed, the difference being that glFlush() returns immediately where as glFinish() blocks until all the...

Is it correct C99 that you don't need to specify arguments in function pointer declarations in structs?

I have written the following C99 code and was wondering about the struct declaration. In it i declare two function pointers which ultimately point to the two push/pop methods in the main code. In the function pointer declarations i've ommited the arguments and the program compiles ok. Is this correct? I'm sure i've read that the argument...

Can I designate a Java-like 'constructor' in c?

I want to 'construct' (read: malloc and memset) my hashtable in c. To do this, I created a function as follows: int maketable(struct hash_entry **table, int size){ table = (struct hash_entry **)malloc(size*sizeof(struct hash_entry *)); int i = 0; for (; i<size; i++) { memset(table[i], '\0', sizeof(struct hash_entry...

delete all shared memory and semaphores on linux

how can i delete all NOT USED semaphores and shared memory with a single command in ubuntu?? ...

Recommend C front-end that preserves preprocessor directives.

I'd like to start a project that involves transforming C code, but I'd like to include the preprocessor directives. I don't want to reinvent the wheel by writing my own C parser, so does anyone know of a front-end that can parse C preprocessor and C code, and produce an AST that can be used to re-generate (or pretty-print) the original ...

Visual Studio 2010 C++ compiler - Get current line number when compiling

Hello, i have a question about how to get the current line number while compiling of the VS C++ compiler, IF its possible of course. I know its possible to use the LINE Macro from the preprocessor, but the results i get are not correct (well, at least not what i want). Please tell me its possible :) Thanks in advance edit: I think i...

c/c++: Curious question about calling function with no arguments with function which returns nothing

Hello, this wierd question just came to my mind. Why isnt it possible to call a function which takes no arguments with a function call as argument which does not return any value (which imho is equivalent to calling a function which takes no arguments with no arguments). f.e. void foo(void) {...} void bar(void) {...} foo(bar()) Don...