Created
May 12, 2025 18:03
-
-
Save kripken/71208023885a553f91acd8313dfd8b09 to your computer and use it in GitHub Desktop.
C++ global object init priority
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
struct A { | |
A() { std::cout << "A\n"; } | |
}; | |
struct B { | |
B() { std::cout << "B\n"; } | |
}; | |
// Init priority adjustment so A is inialized later. | |
A __attribute__ ((init_priority (250))) a; // 150 vs 250 flip the order | |
B __attribute__ ((init_priority (200))) b; | |
int main() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment