>And before you complain about that being a compiler extension yes, it is, but it's also not rare, either, and you're probably using C libraries that do this.
e.g. All Linux kernel modules use this for initialising static structs for interfacing with the kernel.
It's a compiler "hack" for shared libraries, because there is no other way to run initialization for elf objects. [1] The C standard doesn't allow it. And gcc forces you to be explicit about it.
[1]: https://www.geeksforgeeks.org/__attribute__constructor-__att...
#include <stdio.h>
static volatile int* x; static int y = 42;
void __attribute__((constructor)) foo() { printf("[foo] x = %p\n", x); }
int main() { x = &y; printf("[main] x = %p\n", x); return 0; }
And before you complain about that being a compiler extension yes, it is, but it's also not rare, either, and you're probably using C libraries that do this.