- 论坛徽章:
- 0
|
看看我写的这边文章
http://blog.chinaunix.net/u2/76292/showart_1915087.html
- [root@mip-123456 attribute]# cat attribute.c
- #include <stdio.h>
- #include <stdlib.h>
- char* const_foo() __attribute__ ((const));
- void before_main() __attribute__ ((constructor));
- void after_main() __attribute__ ((destructor));
- void __foo() { printf("this is foo\n");}
- void f() __attribute__ ((weak,alias("__foo")));
- char* const_foo()
- {
- char* err = (char*)malloc(10*sizeof(char));
- sprintf(err,"%s","hello");
- return err;
- }
- void before_main() { printf("before main\n");}
- void after_main() { printf("after main\n");}
- int main()
- {
- char* str;
- __foo();
- f();
- str = const_foo();
- free(str);
- str = NULL;
- return 0;
- }
- [root@mip-123456 attribute]# ./attribute
- before main
- this is foo
- this is foo
- after main
复制代码
你可以搜索linux c __attribute__ |
|