Skip to content

Instantly share code, notes, and snippets.

@engie
Created October 15, 2010 09:46
Show Gist options
  • Save engie/627926 to your computer and use it in GitHub Desktop.
Save engie/627926 to your computer and use it in GitHub Desktop.
Reminding myself of the order of static initialisation.
#include <stdio.h>
class C
{
public:
C()
{
printf("Created C\n");
}
};
C& getC()
{
printf("In function\n");
static C c;
printf("Below static initialiser.\n");
return c;
}
int main(int argc, char **argv)
{
printf("Starting\n");
C& c = getC();
printf("Done\n");
}
@engie
Copy link
Author

engie commented Oct 15, 2010

Outputs:
Starting
In function
Created C
Below static initialiser.
Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment