c

how to write default structure values multiple times using fwrite()

Hi I want to write a default structure, N times, to a file, using fwrite. typedef struct foo_s { uint32 A; uint32 B; char desc[100]; }foo_t; void init_file(FILE *fp, int N) { foo_t foo_struct = {0}; foo_struct.A = -1; foo_struct.B = 1; fwrite(&foo_struct, sizeof(foo_struct), N, fp); } The above code does not wri...

Freeing in an atexit()

Is there any point to freeing memory in an atexit() function? I have a global variable that gets malloc'ed after startup. I could write an atexit() function to free it, but isn't the system going to reclaim all that memory when the program exits anyway? Is there any benefit to being tidy and actively cleaning it up myself? ...

Use "greater than or equals" or just "greater than"

I remember from C days that we were encouraged to use i > -1 instead of i >= 0 because of performance. Does this still apply in the C# .NET world? What are the performance implications of using one over the other with today's compilers? i.e. Is the compiler clever enough to optimize these for you? (As an aside try and type the qu...

Cuckoo hashing in C

Does anybody have an implementation of Cuckoo hashing in C? If there was an Open Source, non GPL version it would be perfect! Since Adam mentioned it in his comment, anyone knows why it is not much used? Is it just a matter of implementation or the good theoretical properties do not materialize in practice? ...

What does a type followed by _t (underscore-t) represent?

This seems like a simple question, but I can't find it with the Stack Overflow search or Google. What does a type followed by a _t mean? Such as int_t anInt; I see it a lot in C code meant to deal closely with hardware—I can't help but think that they're related. ...

What is the difference between sigaction and signal?

I was about to add an extra signal handler to an app we have here and I noticed that the author had used sigaction to set up the other signal handlers. I was going to use signal. To follow convention I should use sigaction but if I was writing from scratch, which should I choose? ...

Does Delphi have any equivalent to C's volatile variable?

In C and C++ a variable can be marked as volatile, which means the compiler will not optimize it because it may be modified external to the declaring object. Is there an equivalent in Delphi programming? If not a keyword, maybe a work around? My thought was to use Absolute, but I wasn't sure, and that may introduce other side effects....

Binary "tail" a file

I would guess most people on this site are familiar with tail, if not - it provides a "follow" mode that as text is appended to the file tail will dump those characters out to the terminal. What I am looking for (and possibly to write myself if necessary) is a version of tail that works on binary files. Basically I have a wireless link ...

What's the best way to return a random line in a text file using C?

What's the best way to return a random line in a text file using C? It has to use the standard I/O library (<stdio.h>) because it's for Nintendo DS homebrew. Clarifications: Using a header in the file to store the number of lines won't work for what I want to do. I want it to be as random as possible (the best being if each line has a...

So you think you know pointers?

I was shown this recently, and thought this was a really cool piece of code. Assume 32-bit architecture. #include <stdio.h> int main(void) { int x[4]; printf("%p\n", (void*) (x)); printf("%p\n", (void*) (x + 1)); printf("%p\n", (void*) ( printf("%p\n", (void*) ( } Without compiling the program, what does it output...

What is the difference between these declarations in C?

Hi friends, I am Manoj here to ask a question again. In C and C++ what do the following declarations do? const int * i; int * const i; const volatile int ip; const int *i; Are any of the above declarations wrong? If not what is the meaning and differences between them? What are the useful uses of above declarations (I mean in whic...

Malloc Error: incorrect checksum for freed object

I am working on implementing tail for an assignment. I have it working correctly however I seem to be getting an error from free at random times. I can't see, to track it down to a pattern or anything besides it is consistent. For example if I call my program as "tail -24 test.in" I would get the the the incorrect checksum error at the...

what is the difference between c and embedded c?

can any body tell me the differences between them? ...

How can I get the size of an array from a pointer in C?

I've allocated an "array" of mystruct of size n like this: if (NULL == (p = calloc(sizeof(struct mystruct) * n,1))) { /* handle error */ } Later on, I only have access to p, and no longer have n. Is there a way to determine the length of the array given just the pointer p? I figure it must be possible, since free(p) does just that. ...

Including one C source file in another?

Is it OK (or even recommended/good practice) to #include .c file in another .c file? What happens when they are included in a project file? ...

use of #pragma in c

can u tell me usage of #pragma in c with an example ...

Changes to the C standard for a modern world

Having just answered a question on what the #pragma direction does in C, and had some fun with it, I was thinking of what other useful directives we could add to the language to keep pace with the stresses faced by todays developer. My first one was #dogma, basically there to counteract all the pragmatic stuff creeping into modern C an...

How to set the Turbo C path in windows?

hi friends, I am Manoj again here to ask my doubts How to set the turbo c path in windows globally? so that i can compile and run my c progrmas which are in other drives any where in the command prompt in windows XP. Can any one tell me how to get commands at evry drive in the command prompt just by typing in "c:\tcc" in command prompt i...

Can any body tell me what is list file and map file in c?

hello friends, I am Manoj again here to ask you my doubts. I heard that in turbo c when we are doing projects with more than one source file then we can generate list file and map file . What are they? what do they contain? And how to generate them using the commands at MS-DOS command prompt using tcc for turbo c? How to generate the ass...

How to include the assembly code in my C code in Turbo C?

hello friends, How to include any assembly code lines into my C program ? In turbo c is there a possibility to add an assembly code file (.asm) to a project of few .c files? ...