??? 06/16/04 07:58 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#72566 - RE: Static Local Variable Vs Global Variable Responding to: ???'s previous message |
For completeness, let's consider all the possible cases:
unsigned char global_variable; static unsigned char static_global_variable; void func( void ) { unsigned char local_variable; static unsigned char static_local_variable; : : { unsigned char inner_local_variable; static unsigned char static_inner_local_variable; } }global_variable, static_global_variable, static_local_variable, and static_inner_local_variable all exist permanently in memory, so they will retain their contents until specifically modified - the difference is in accessibility: global_variable can be accessed by anything throughout the entire system - including functions in other souurce files (it has global scope); static_global_variable can be accessed only within the current source file (if has file scope); static_local_variable can be accessed only within the function func; static_inner_local_variable can be accessed only within its inner block within the function func. local_variable only exists within the function func - its memory may be re-used outside that function and, therefore, it will not retain its value between calls to func. inner_local_variable only exist within the inner block inside function func - its memory may be re-used outside that block and, therefore, it will not retain its value outside that block (and certainly not between calls to func). |
Topic | Author | Date |
Static Local Variable Vs Global Variable | 01/01/70 00:00 | |
RE: Static Local Variable Vs Global Variable | 01/01/70 00:00 | |
Not 8051-Specific | 01/01/70 00:00 | |
RE: Static Local Variable Vs Global Variable | 01/01/70 00:00 | |
RE: Static Local Variable Vs Global Variable | 01/01/70 00:00 | |
RE: Static Local Variable Vs Global Variable | 01/01/70 00:00 | |
RE: Static Local Variable Vs Global Variable | 01/01/70 00:00 | |
RE: Static Local Variable Vs Global Variable | 01/01/70 00:00 | |
RE: Static Local Variable Vs Global Variable | 01/01/70 00:00 | |
RE: Static Local Variable Vs Global Variable![]() | 01/01/70 00:00 |