Initialize a variable with a pointer to this variable

In C, are the following clearly defined?

void* ptr = &ptr; void* array[1] = {array}; 

In other words, can you use the address of a variable to initialize this variable? It seems to work with the GCC compiler, but I just want to know what I can rely on.

Edit: is it essentially a duplicate of a pointer definition for a link to a link with the same variable name?

+5
source share
1 answer

SHOULD be legal. Since ptr is not const, its initialization value is not fixed in the .text code area and therefore must be known at runtime and written to RAM with the correct value.

0
source

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


All Articles