Hi everyone,
I would like to know if something similar happen to you. Well the issue is that when I declare a variable as a global one in the header file of a module with extern sometimes it loses its value. And if I declare it as static I can not access to it from other module. As far As I understand, a static variable is the same during the all of the execution of the program and it has a space of memory reserved to it. Can anyone please clarify this?
Thanks in advance.
The thread title speaks of 'static'...
Quite unfornuately the word "static" means just enough different things in discussions about C programming (let alone C++ or Java) that its mention alone means either everything or nothing at all. Overloading 'static' to mean two such different things as "static duration" and "internal linkage" may have to be called the worst design decision in the C programming language.
The OP's code fragment shown mid-thread, which we seem to be discussing now, had no 'static'. If there had been a "static" in that header fragment, it would have collided with the "extern" in the C source, and caused a compilation error.
So while it's possible that the OP's real code (which is probably quite different from the fragments shown) contains a strategically well-misplaced "static", I'll consider that highly unlikely until confirmed by OP.