Dev Tool Tips/C/C++2011. 11. 13. 17:52

main() 함수보다 먼저 시작하고 메인 함수가 끝난 뒤에도 실행되는 함수

/* ---  test.c START  --- */
#include <stdio.h>

void hello(void) __attribute__ ((constructor)) ;
void goodbye(void) __attribute__ ((destructor)) ;

void hello(void)
{
        printf("Hello\n");
}

void goodbye(void)
{
        printf("BYE\n");
}

int main(int argc, char** argv)
{
        printf("==== main === \n");
        return 0;
}
/* ---  test.c END  --- */

$ cc test.c
$ ./a.out
Hello
==== main ===
BYE

Posted by young.h.rhie