I am working on a large C project for a company.
I have realized that some times in the compiled executable, static variables used in C files are not initialized to zero and have some value in them. But when I edit the code a bit, like adding a print statement any where in the project, the issue is resolved.
I am using a Broadcom STB mips cross-compiler toolchain for compiling the codes.
The program is run on a Broadcom 97241 chipset running Linux 3.1.3.
[EDIT] I tried a clean build also but the problem did not go away.
The C standard requires that
staticvariables must be initialized at the start of the program. If you don't initialize them, then the compiler will initialize them to 0. So if you are using normal compiler, then all yourstaticvariables are initialized to 0 if you don't initialize them explicitly. Such problems may occur if:1) Some of your code set the value to a static variable.
2) The compiler is not
Ccompiler.3) Your program damage the memory and then you can't rely on assertions, on
printf(), e.t.c.Anyway. Try to initialize static variables to 0 explicitly. (to cut the 2 point off). And hope there is a way to debug your application. Debugger is much more useful in such problems, then asking such abstract question here.