Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enumerator attributes in GCC

Tags:

c

enums

gcc

GCC's online documentation claims it supports enumerator attributes:

GCC allows attributes to be set on enumerators.

It then gives a code example using such attributes:

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

 int
 fn (void)
 {
   return oldval;
 }

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)),
               ^

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

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

like image 279
anol Avatar asked Nov 26 '25 17:11

anol


1 Answers

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.

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.

like image 86
Shafik Yaghmour Avatar answered Nov 28 '25 16:11

Shafik Yaghmour