Skip to content

Instantly share code, notes, and snippets.

@darcyliu
Created July 2, 2019 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darcyliu/9ea06e69d1022a7136c644335af230fa to your computer and use it in GitHub Desktop.
Save darcyliu/9ea06e69d1022a7136c644335af230fa to your computer and use it in GitHub Desktop.
Clang constructor and destructor attributes
// 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