Last active
December 2, 2016 18:03
-
-
Save Gaurav-Singh-97/07c1d4277285e40e7209513c4027cfb1 to your computer and use it in GitHub Desktop.
Running functions before and after main() (works on gcc and g++)
This file contains 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
/* | |
Usage : | |
"test.cpp" | |
---------- | |
#include <iostream> | |
#define _START_ begin | |
#define _EXIT_ end | |
#include "Startup_Exit.h" | |
void begin() | |
{ | |
std::cout << "Running before main()\n"; | |
} | |
void end() | |
{ | |
std::cout << "Running after main()\n"; | |
} | |
int main() | |
{ | |
std::cout << "Running main\n"; | |
} | |
*/ | |
#ifndef START_EXIT_H | |
#define START_EXIT_H | |
#ifdef __GNUC__ | |
void _START_ (void) __attribute__((constructor)); | |
void _EXIT_ (void) __attribute__((destructor)); | |
#endif | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment