Is the address of a global variable guaranteed to remain unchanged during process execution?

Is the address of a global variable guaranteed to say the same thing throughout the execution process? That is, I have

static int dummy;

and i use

something(&dummy);

in several different places in my code. Will it &dummyever change, or can I safely use it as a key that is unlikely to be reused by another library (for example, in hashmap)?

This, of course, suggests that I do not restart the program or reload the library.

(Context: It was recommended to me by some people on the Lua mailing list. I used it here .)

+4
2

, C11§6.2.4:

[2] - , . , , 33) . 34) , undefined. , , ( ), .

[3] , _Thread_local , static, . - program, , .

33:

33) " " , , . .

+2

. C99:

[6.2.4] - , . , .

+4

Source: https://habr.com/ru/post/1611168/


All Articles