LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1116|回复: 3

对于 __attribute__((noreturn))类似的语句,noreturn段这么做有什么作用?

[复制链接]
发表于 2005-7-2 17:58:52 | 显示全部楼层 |阅读模式
我最近在读某程序的源码,看到下面的定义:
static void show_dlts_and_exit(pcap_t *pd) __attribute__((noreturn));

查资料之后,得到下面的描述:
       Normally, the compiler places the code it generates in the `text'
   section. Sometimes, however, you need additional sections, or you
   need certain particular functions to appear in special sections.
   The `section' attribute specifies that a function lives in a
   particular section. For example, the declaration:

     extern void foobar (void) __attribute__ ((section ("bar")));

   puts the function `foobar' in the `bar' section.

   Some file formats do not support arbitrary sections so the
   `section' attribute is not available on all platforms. If you
   need to map the entire contents of a module to a particular
   section, consider using the facilities of the linker instead.

那么,
1.对于section来说,这是可以随意由程序员定义的吗?
2.这样的段和我们说的代码段,数据段有什么关系吗?或者他们只是在不同的技术中用的不同的术语.
3.这种section有什么用处?
发表于 2005-7-3 10:13:40 | 显示全部楼层
__attribute__关键字主要是用来在函数或数据声明中设置其属性。给函数赋给属性的主要目的在于让编译器进行优化。函数声明中的__attribute__((noreturn)),就是告诉编译器这个函数不会返回给调用者,以便编译器在优化时去掉不必要的函数返回代码。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-7-3 10:53:31 | 显示全部楼层
Post by kj501
__attribute__关键字主要是用来在函数或数据声明中设置其属性。给函数赋给属性的主要目的在于让编译器进行优化。函数声明中的__attribute__((noreturn)),就是告诉编译器这个函数不会返回给调用者,以便编译器在优化时去掉不必要的函数返回代码。


这么说来...我理解错了.
那些属性值都是GCC定义的有限几个值吗?


Thanks,kj501
回复 支持 反对

使用道具 举报

发表于 2005-7-3 12:31:02 | 显示全部楼层
info gcc 可以看到更详细的解释。这些属性都是gcc特有的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表