main()の前後で関数を呼び出す
#include <stdio.h> __attribute__((constructor)) void foo() { printf("hello, before main\n"); } __attribute__((destructor)) void bar() { printf("hello, after main\n"); } int main(int argc, char const *argv[]) { printf("hello, world\n"); return 0; }
$ gcc test.c $ ./a.out hello, before main hello, world hello, after main