Created
July 2, 2019 05:27
-
-
Save darcyliu/9ea06e69d1022a7136c644335af230fa to your computer and use it in GitHub Desktop.
Clang constructor and destructor attributes
This file contains hidden or 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
// clang attribute.c -o attribute | |
#include <stdio.h> | |
int main(int argc, char *argv[]) { | |
printf("Hello World!\n"); | |
return 0; | |
} | |
__attribute__((constructor)) static void beforeFunction() | |
{ | |
printf("beforeFunction\n"); | |
} | |
__attribute__((destructor)) static void afterFunction() | |
{ | |
printf("afterFunction\n"); | |
} | |
__attribute__((constructor(101))) static void before1() | |
{ | |
printf("before1\n"); | |
} | |
__attribute__((constructor(102))) static void before2() | |
{ | |
printf("before2\n"); | |
} | |
__attribute__((constructor(102))) static void before3() | |
{ | |
printf("before3\n"); | |
} | |
__attribute__((destructor(101))) static void after1() | |
{ | |
printf("after1\n"); | |
} | |
__attribute__((destructor(102))) static void after2() | |
{ | |
printf("after2\n"); | |
} | |
__attribute__((destructor(103))) static void after3() | |
{ | |
printf("after3\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment