??? 03/16/09 06:51 Read: times |
#163478 - Nothing magic with "static" Responding to: ???'s previous message |
Nothing magic about the "static" keyword.
When used with a function or a global variable, it will just inform the compiler that the function or variable should only be accessible within that specific C file, so it need not "pollute" the global namespace by creating external references for the linker. A function declared "static" does not change its behaviour. The program will work just as well, unless you try to access this function from another source file (C or assembler). Then the linker will fail to finding the required symbol. When writing modular code, it is a good thing to keep down the number of symbols visible globally. This is probably the reason why your lint program has suggested that you add static to functions and variables it notices you are not using from other source files. Note however the difference of the keyword "static" with a function name or global variable, in compariston to "static" used with a local (auto) variable in a function. When you declare a local variable as static, it will not be placed on the stack, but will become a global nameless variable only accessible by that specific function. So it will remember the value between separate calls to the function. |
Topic | Author | Date |
Can ISR functions be made 'static'? | 01/01/70 00:00 | |
What does 'static' mean? | 01/01/70 00:00 | |
Nothing magic with "static" | 01/01/70 00:00 | |
'static' local variables | 01/01/70 00:00 | |
Difference between normal auto and static auto.![]() | 01/01/70 00:00 |