I need to allocate an array according to how many elements the enum have. I did the following:
enum { A, B, C, LAST };
char buf[LAST];
That works fine,even with -ansi -pedantic flags. But I’m not sure if it’s a GCC or clang(wich supports most,if not all GCC-extensions) extensions or really allowed by the ANSI C standard and will works fine in any C compiler with ANSI-C std. Can someone clarify it?
Both the C89 (section 3.5.2.2) and C99 (section 6.7.2.2) standards define enums the same way:
Both read:
Therefore, in your syntax, any standard-compliant compiler will run your code correctly.