当前位置: 首页 >> 程序设计 >> Linux 内核使用的 GNU GCC 的C 扩展
 

Linux 内核使用的 GNU GCC 的C 扩展

作者:      来源:linuxforum.net     发表时间:2006-03-16     浏览次数:      字号:    

      tester (int len, char data[len][len]){



       }



15.可变量参数的宏( macros with variable number of arguments)

   in Gcc:

      #define debug(format, ...) fprintf(stderr, format, __VA_ARGS__)

      "..."是一个可变参数



16.slightly looser rules for escaped newlines



17.string literals with embedded newlines



18.non-lvalue arrays may have subscripts

   in Gcc:

   struct foo{ int a[4]};

   struct foo f();

   bar (int index){

       return f().a[index];

   }



19.void- 和 function-pointers 的转换( arithmetic on void- and function-pointer)

   arg with gcc:

       -Wpointer-arith  -- to warning if the arithmetic are used



20.非常数初始化( non-constant initializers )

   in Gcc:

      foo(float f, float g){

         float beat_freqs[2] = { f-g, f+g };

      }



21.字面上的组合( compound literals )



22.指明的初始化( designated initializers )

   in Gcc:

      int a[6] = { [4] = 29, [2] = 15};

      int withs[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3};



23. case ranges



24. cast to a union type

                

25. mixed devlarations and code



26. declaring attributes of functions

    in Gcc:

    __attribute__

    total 14 attributes: noreturn, pure, const, format, format_arg,
no_instrument_function, section, constructor, destructor, unused, weak, malloc, alias,
no_check_memory_usage,regparm(number),stdcall,cdecl,longcall,short_call....





27.属性语法(attribute syntax)

本节描述__attribute__可能用到的语法,和在C中属性特殊绑定的构造,一些细节会多样的对C++?br>蚾bjective C.因为属性文法的不幸,一些在这里描述的格式不能被全部成功地分析。

  see 5.26 [function attributes]

      5.33 [variable attributes]

      5.34 [type attributes]

一个属性指示是格式__attribute__((attribute-list))

一个属性列表可能是一个空的逗号隔开的属性序列,每一个属性是下列中的一个:

  1.空

  2.字

  ......

一个属性指示表(attribute specifier list)是一个或多个属性指示,不被任何记号分离

一个属性指示可以出现在标号的冒号后面,除了 case , default

但是它是不用的(unused),但是要用'-Wall'编译



一个属性指示可以是struct, union, enum 指示的一部分,如果struct,union,enum为空则忽略它



另外,一个属性指示可以是一个申明,未名命的计数申明和类型名的一部分



以后,一个属性指示在很多地方作为一个特殊申明符代替了,一些例子在下面



当一个属性指示申明为函数或矩阵的参数,他会付给函数隐含的盖住参数的指针,但是这个现在还没
有真确的实现



任何指示的列表在??????? p172.s4



一个属性指示列表能出现在一个声明前面,而且对他后面的申明都有效

__attribute((noreturn)) void d0(void), __attribute__((format(printf,1,2))) d1(const
char *, ...), d2(void)

其中'noreturn'对全部申明,'format'只能为d1声明,如果为d2声明则产生错误



一个属性指示列表能出现在逗号(,),等号("),分号(")



(****f)(void)
__attribute__((noreturn)),现在'noreturn'属性申明到f,导致警告f不是一个函数,但是以后将
能申明到这个函数 ****f



???

???

???  p173



28.原形和经典风格的函数定义



29.C++风格的注释



30.带美金符号的名字



31.'ESC'常数

ascii ESC = 'e'



32.追根究底的变量和类型对齐

   __alignof__(foo)

   exp:

   __alignof__(double) is 8 on may RISC

   __alignof__(double) is 4 or even 2 on more tradidional machine



33.变量的属性

   8 attributes:

     aligned, mode, nocommon, packed, section, transparent_union, unused, weak,
share(only in WinNT)

    

    NOTE:

     mode(mode): byte, __byte__, word, __word__, pointer, __pointer__

 

     nocommon:
用'-fno-common'编译,将会将全部的变量编译为nocommon,直接分配空间给它,并全部置为0,一个?br>淞恐荒茉谝桓鲈次募

[1] [2] [3]

编辑 webmaster

 
 
 
评论更多>>
 
 
发表
 
姓名: QQ:
性别: MSN:
E-mail: 主页:
评分: 1 2 3 4 5
评论内容:
验证码:
  
  • 请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
  • 严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
  • 用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表网友个人观点,与本网站立场无关。
  •