Skip to content

Instantly share code, notes, and snippets.

@kripken
Created May 12, 2025 18:03
Show Gist options
  • Save kripken/71208023885a553f91acd8313dfd8b09 to your computer and use it in GitHub Desktop.
Save kripken/71208023885a553f91acd8313dfd8b09 to your computer and use it in GitHub Desktop.
C++ global object init priority
#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