I'm working with two independent c/c++ applications on Windows where one of them constantly updates an image on disk (from a webcam) and the other reads that image for processing. This works fine and dandy 99.99% of the time, but every once in a while the reader app is in the middle of reading the image when the writer deletes it to refr...
#define fileSize 100000
int main(int argc, char *argv[]){
char *name=argv[1];
char ret[fileSize];
FILE *fl = fopen(name, "rb");
fseek(fl, 0, SEEK_END);
long len = fileSize;
fseek(fl, 0, SEEK_SET);
//fread(ret, 1, len, fl);
int i;
*(ret+fileSize) = '\0';
...
Anyone have recommendations for a good C editor for Windows? Any improvement over the Emacs over ssh setup I have right now would be appreciated.
...
I have an array of bytes, in memory. What's the fastest way to see if all the bytes in the array are zero?
...
I need a big null array in C as a global. Is there any way to do this besides typing out
char ZEROARRAY[1024] = {0, 0, 0, /* ... 1021 more times... */ };
?
...
After the boot loader hands execution over to the kernel, what happens? I know assembler, so what are the first few instructions that a kernel must make? Or is there a C function that does this? What is the startup sequence before the kernel can execute an arbitrary binary?
...
Lets say within my program I want to execute two child processes, one to to execute a "ls -al" command and then pipe that into "wc" command and display the output on the terminal. How can I do this using pipe file descriptors so far the code I have written: An example would be greatly helpful
int main(int argc, char *argv[]) {
int pipef...
I have read a lot of posts about "string literals" on SO, most of which have been about best-practices, or where the literal is NOT located in memory.
I am interested in where the string DOES get allocated/stored, etc.
I did find one intriguing answer here, saying:
Defining a string inline actually embeds the data in the program it...
I'm writing a program to check to see if a port is open in C. One line in particular copies one of the arguments to a char array. However, when I try to compile, it says:
error: incompatible types in
assignment
Heres the code. The error is on the assignment of addr
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/type...
What exactly happens, in terms of memory, when i declare something like:
char arr[4];
How many bytes are reserved for arr?
How is null string accommodated when I 'strcpy' a string of length 4 in arr?
I was writing a socket program, and when I tried to suffix NULL at arr[4] (i.e. the 5th memory location), I ended up replacing the value...
I'm learning C++ from scratch, and as such I don't have an expert understanding of C. In C++, you can't cast a void pointer to whatever, and I understand the reasons behind that. However, I know that in C, you can. What are the possible reasons for this? It just seems like it's be a huge hole in type safety, which (to me) seems like a ba...
I'm working in the JNI Invocation API, calling into Java from C. I have some upfront initialization to cache 30+ Java classes into global references. The results of FindClass are passed into NewGlobalRef to acquire a global reference to the class. I'm caching these class variables to reuse them later. I have 30+ global references to ...
Can anyone tell me what the gcov message "Merge mismatch for summaries" means? I have found the message in the gcc source here:
http://www.opensource.apple.com/source/gcc/gcc-5646/gcc/libgcov.c
It seems to be a sanity check that the tags in the .gcda files match, but I'm not sure. Anyone know how to work around this?
...
Hi,
I am using linux, gcc, c.
I have a make file.
I want to debug my module.
How can I do it?
I don't want to debug a single file, I want to debug the whole module.
...
In Visual C++ i wrote the following sample in a C++ program:
float f1 = 42.48f;
double d1 = 42.48;
double d2 = f1;
I compiled the program with Visual Studio 2005.
In the debugger i see the following values:
f1 42.480000 float
d1 42.479999999999997 double
d2 42.479999542236328 double
d1 by my knowledege is OK, but d2 is wron...
suppose i declared a macro name anything, xyz()
and now i am creating another macro xyz1() and referencing the 1st macro i.e xyz() in 2nd.
finally i'll create another macro xyz2() and referencing 2nd macro in 3rd...
now my question is is this correct(its executing without any problem)..?
and macro xyz() is defined twice.... why its no...
Hi, I would like to know what lines of C code to add to a program so that it tells me the total time that the program takes to run. I guess there should be counter initialization near the beginning of main and one after the main function ends. Is the right header clock.h?
Thanks a lot...
Update I have a Win Xp machine. Is it just addin...
What advantage (if any) is there to using typedef in place of #define in C code?
As an example, is there any advantage to using
typedef unsigned char UBYTE
over
#define UBYTE unsigned char
when both can be used as
void func()
{
UBYTE byte_value = 0;
/* Do some stuff */
return byte_value;
}
Obviously th...
I'm looking for a "best practice" to document my C code. Like in any project I have some header files ".h" and the respective source file ".c"
In the header file what kind of comment you put in? And in source files?
The question arise up because since I commented well my header files, the c files looks like a mess.
What's your best pra...
I want to extensively test some pieces of C code for memory leaks.
On my machine I have 4 Gb of RAM, so it's very unlikely for a dynamic memory allocation to fail. Still I want to see the comportment of the code if memory allocation fails, and see if the recover mechanism is "strong" enough.
What do you suggest ? How do I emulate an en...