static structs?
Hi all,
I am quite confused over a bit of code in C. Now here's my problem there is a function below, and this function gets called by a bunch of other functions. (Note: this is not in main()). struct eToken * get_token_by_lun(DWORD Lun){ static struct eToken eToken; if(Lun==0) return &eToken; return NULL; } now what happens everytime this function gets called, does it create a new eToken every single time?, ot does it create it first time, and never again?I'm confused by the static part, 'cause i thought static meant it's always there. Thanks in advance, Sim |
The function will return a pointer to the same eToken every time it's called -- it will behave exactly as if the eToken variable was a global variable. If you want to return a new eToken every time, you'll have to use malloc() to allocate memory dynamically.
Alex |
Cheers
oh ok, so it will be the same even if the calling functions modify that struct, correct me if i'm wrong. Thanks a lot for your help.
Sim |
Yes, that's right.
Alex |
All times are GMT -5. The time now is 06:50 AM. |