I'm using the Yagarto GCC compiler and I'm finding problems when using local static variables. All of them are initialized by me to zero when declaring it. But when debugging execution, I find they are not being initialized:
Example:
void hello( void ){
static int number_hellos = 0;
number_hellos++;
printf("%d\n", number_hellos);
}
When debugger reaches number_hellos++
, I find its initial value is not 0. Why? Is there any compiler or linker flag I should enable?
This static initialization:
static int number_hellos = 0;
happens only once. Actually in compile time. Not when entering the function.
Thanks for your help
Finally I detected the problem: The startup code was not correctly initializing the static variables. That's the reason why the execution arrives to the function hello, the static variable is unitialized.
A correct startup code fixes the problem.
Thanks again
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.