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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With