Skip to content

Instantly share code, notes, and snippets.

@opsJson
Last active December 25, 2021 23:32
Show Gist options
  • Save opsJson/f1d41caf72ac93b32c8e031a6df5d93f to your computer and use it in GitHub Desktop.
Save opsJson/f1d41caf72ac93b32c8e031a6df5d93f to your computer and use it in GitHub Desktop.
Execute code before and after main function.
#include <stdio.h>
void before_main() {
printf("code before main here.\n");
}
void after_main() {
printf("code after main here.\n");
}
int __main__(int argc, char **argv);
int main(int argc, char **argv) {
before_main();
__main__(argc, argv);
after_main();
}
#define main(...) __main__(int argc, char **argv)
/*///////////////////////////////////
Testing:
///////////////////////////////////*/
int main() {
printf("Hello World\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment