免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4622 | 回复: 1

[C] attribute_hidden和weak_alias是哪里定义的?自己写程序可以用吗? [复制链接]

论坛徽章:
0
发表于 2009-07-10 18:56 |显示全部楼层
5可用积分
找不到他们的说明
请问自己写程序的时候也可以用吗?他们定义在哪里?

论坛徽章:
0
发表于 2009-07-11 09:41 |显示全部楼层
看看我写的这边文章
http://blog.chinaunix.net/u2/76292/showart_1915087.html

  1. [root@mip-123456 attribute]# cat attribute.c
  2. #include <stdio.h>
  3. #include <stdlib.h>

  4. char* const_foo() __attribute__ ((const));
  5. void before_main() __attribute__ ((constructor));
  6. void after_main() __attribute__ ((destructor));

  7. void __foo() { printf("this is foo\n");}
  8. void f() __attribute__ ((weak,alias("__foo")));

  9. char* const_foo()
  10. {
  11. char* err = (char*)malloc(10*sizeof(char));
  12. sprintf(err,"%s","hello");
  13. return err;
  14. }


  15. void before_main() { printf("before main\n");}
  16. void after_main() { printf("after main\n");}

  17. int main()
  18. {
  19. char* str;
  20. __foo();
  21. f();
  22. str = const_foo();
  23. free(str);
  24. str = NULL;

  25. return 0;
  26. }

  27. [root@mip-123456 attribute]# ./attribute
  28. before main
  29. this is foo
  30. this is foo
  31. after main
复制代码

你可以搜索linux c __attribute__
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP