当前位置: 动力学知识库 > 问答 > 编程问答 >

gcc - What C GNU-isms exist?

问题描述:

I was recently porting a project from GCC to clang(in which I fixed a number of C GNU-isms). This got me thinking: what C GNU-isms(extensions to the C language supported in GCC, which are not standardized) exist? Is there a comprehensive list anywhere?

网友答案:

Here is a pretty comprehensive list straight from GCC's website. There seems to be quite a lot, so I wish you the best of luck sifting through it!

http://gcc.gnu.org/onlinedocs/gcc-4.2.0/gcc/C-Extensions.html

网友答案:

One of the nicest GNUisms I found was explicit key declaration while filling structures.

 struct canmsg_t {
      short     flags;
      int       cob;
      canmsg_id_t   id;
      unsigned long timestamp;
      unsigned int  length;
      unsigned char data[CAN_MSG_LENGTH];
 };

 canmsg_t msg = 
 {
      ["flags"] = 0x00;
      ["cob"]   = 0;
      ["id"]    = 0x534;
      ["timestamp"] = 0;
      ["length"] = 1;
      ["data"] = { 0 };
 }

This does not allow to skip members or reorder them, just throws an error if you do so, but with 100+ element structures this becomes invaluable.

网友答案:

Although there are many extensions, and I defer to Beta's answer for that, it is unlikely that your project relies upon many of them. It is possible to disable extensions in a GNU build, so simply doing that will give you advance warning of any potential incompatibilities in your code base.

You may encounter other problems such as the fact that GCC supports most C99 features, whereas some popular compilers do not (Microsoft VC++ specifically). So you may want to disable C99 features too when you test the code base.

分享给朋友:
您可能感兴趣的文章:
随机阅读: