Non-Standard GNU C/C++ Features (aka Extensions)

Article by:
Date Published:
Last Modified:


GNU offers some non-standard features in their C and C++ compilers. They call these extensions. I do not recommend using extensions where possible, they are extremely compiler specific and make your code less portable.

That said, they are still sometimes the best tool for the job (e.g. you can’t do something any other way, or the non-compiler specific method is ugly and horrible).

Initialisation Priorities

GNU allows you to determine the initialisation order of global static variables by specifying a priority.

// In some .cpp file...

MyClass myVar1  __attribute__ ((init_priority (321)));
MyClass myVar2  __attribute__ ((init_priority (12)));

Usually, myVar1 would be initialisaed before myVar2. However, with myVar2 being specified with the priority 12 (lower numbers equate to a higher priority), myVar2 will be initialised first.


Geoffrey Hunter

Dude making stuff.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License .


    comments powered by Disqus