在main函数执行之前和执行之后执行的方法

//

//  before&after.c

//  Created by labuser on 10/30/11.

//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.

//

 

#include <stdio.h>

 

void before() __attribute__((constructor));

void after() __attribute__((destructor));

 

void before() {

    //printf("This is function %s\n", __func__);

    fprintf(stdout, "In %s %d\n", __func__, __LINE__);

}

void after() {

    //printf("This is function %s\n", __func__);

    fprintf(stdout, "In %s %d\n", __func__, __LINE__);

}

 

int main(int argc, char* argv[]) {

    atexit(after);

    printf("This is function %s\n", __func__);

    return 0;

}

posted on 2011-10-30 15:50  Cheney Shen  阅读(221)  评论(0编辑  收藏  举报

导航