Not Keil specific; one for the 'C' experts:
Why would one put 'static' variables definitions in a header?
eg, in a header file:
/* * TCO count to temperature conversion table. */ static erTcoTableStruct tcoTableOPUS1[] = { /*{TCO,Temp,} */ {1,-99}, {4,-45}, {5,-40}, {8,-35}, {11,-30}, {16,-25}, {22,-20}, {29,-15}, {37,-10}, {48,-5}, {61,0}, {78,5}, {99,10}, {124,15}, {153,20}, {188,25}, {227,30}, {270,35}, {315,40}, {365,45}, {420,50}, {481,55}, {549,60}, {625,65}, {710,70}, {805,75}, {910,80}, {1010,85}, {1060,88} };
AIUI, the whole point of so-called "header" files in 'C' is to share stuff between source files;
But the whole point of the 'static' keyword (at file scope) in 'C' is to make stuff private so that it is not visible to other modules - ie, not shared.
So I can't see why one would want to have 'static' definitions in a header?!
Tamir,
Although it might look 'complicated' it really isn't. All too many times people will re-include files that don't need to be included, and will sometimes include the wrong file (esp the SFR files).
Using my method, the code is very structured and all include files are in total control via the "Includes.H" file.
This also adds to the reliability of the code, not to mention repeatability during the debug phase.
Any code-monkey who cannot handle this structure should be taken out back and, well you get the idea.
I think once you have tried it, you'll stick with it.
--Cpt. Vince Foster 2nd Cannon Place Fort Marcy Park, VA
Yes, there is merit in having a single header that provides (by conditional compilation) both the definitions and the extern declarations of shared symbols - the practice is quite common.
Just to note that the code in question (in my original post) is not doing any of this definition-here-declaration-there trickery; It's just a straightforward 'static' definition that is included verbatim in any & every file that #includes that header.
Andy,
I think that 'static' does not mean 'private' unless you are declaring a function. Static, from what I remember, means that the data allocation remains in memory and is not optimized out. Thus an 'extern' to a static should be allowed.
Not quite.
static applied to an automatic variable, as you say, makes its storage permanent.
But static applied to a file-scope variable does make it "private" - or, in spec-talk, gives it "internal linkage".