存在哪些 C GNU 主义?

发布于 2024-08-19 12:31:37 字数 105 浏览 4 评论 0原文

我最近将一个项目从 GCC 移植到 clang(其中我修复了一些 C GNU 主义)。这让我开始思考:存在哪些 C GNU 主义(GCC 支持的 C 语言的扩展,但尚未标准化)?哪里有完整的列表?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

魄砕の薆 2024-08-26 12:31:37

这是直接来自 GCC 网站的相当全面的列表。好像还蛮多的,祝你筛选顺利!

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

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

中二柚 2024-08-26 12:31:37

我发现的最好的 GNU 主义之一是在填充结构时显式的键声明。

 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 };
 }

这不允许跳过成员或对它们重新排序,如果这样做只会引发错误,但对于 100 多个元素结构,这变得非常有价值。

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.

半葬歌 2024-08-26 12:31:37

尽管有很多扩展,并且我尊重 Beta 的回答,但您的项目不太可能依赖其中的许多扩展。可以在 GNU 构建中禁用扩展,因此只需这样做即可提前警告您代码库中任何潜在的不兼容性。

您可能会遇到其他问题,例如 GCC 支持大多数 C99 功能,而一些流行的编译器不支持(特别是 Microsoft VC++)。因此,当您测试代码库时,您可能也想禁用 C99 功能。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文