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(ext开发者_运维知识库ensions 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.
精彩评论