Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 440
Mike Avatar asked Sep 01 '25 03:09

Mike


2 Answers

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

like image 130
beta Avatar answered Sep 02 '25 17:09

beta


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.

like image 28
SF. Avatar answered Sep 02 '25 17:09

SF.