在枚举属性GCC [英] Enumerator attributes in GCC

查看:218
本文介绍了在枚举属性GCC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GCC的在线文档声称它支持枚举属性:

GCC's online documentation claims it supports enumerator attributes:

GCC允许的属性要在普查员设置。

GCC allows attributes to be set on enumerators.

它然后使用这些属性给出了一个code例如:

It then gives a code example using such attributes:

 enum E {
   oldval __attribute__((deprecated)),
   newval
 };

 int
 fn (void)
 {
   return oldval;
 }

但是当我尝试在我的海湾合作​​委员会(4.8.4),我得到一个错误:

But when I try it on my GCC (4.8.4), I get an error:

t.c:2:15: error: expected ‘,’ or ‘}’ before ‘__attribute__’
        oldval __attribute__((deprecated)),
               ^

我需要的地方让他们?或使用不同的GCC?

Do I need to enable them somewhere? Or use a different GCC?

注意锵还声称支持这个C扩展,但它锵按预期工作。

Note that Clang also claims to support this C extension, but with Clang it works as expected.

推荐答案

您正在寻找的文件指的是最新的开发分支,但是如果我们去的 gcc的在线文档,我们看的 GCC 5.2手动,这是最新的版本中,我们看不出有任何的属性枚举的部分。这就解释了为什么这个功能在GCC 的头修订工作,但不旧的版本。

The documentation you are looking at refers to the latest development branch, but if we go to gcc online documentation and we look at the gcc 5.2 manual, which is the latest release, we see no Enumerator Attributes section. This explains why it this feature works in the head revision of gcc but not older versions.

所以这是一个相对较新的功能,仅在头分支可供选择,是不是任何其他发行版的一部分,(还)。铛似乎支持此的一路的早在3.0

So this is a relatively new feature that is only available in the head branch and is not part of any other releases(yet). clang seems to support this all the way back in 3.0.

这篇关于在枚举属性GCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆