LCC: Forward Declaration of Typedef'd Enum Failing?
The following code snippet compiles just fine on Mac OS X with gcc, but fails to compile on Windows with lcc-win32:
typedef enum Foo Foo;
// Other code here
enum Foo { Bar = 1 };
And gives this error:
unknown enumeration 'Foo'
In my particular case, this was not a problem. I simply combined the statements into:
typedef enum Foo { Bar = 1 } Foo;
But I'm wonderin开发者_开发知识库g if LCC is being either "more strict" (adhering to some standard) or "more dumb" (the compiler is too dumb to handle this situation).
Thanks.
Also, please see my other LCC question: LCC: Initializing Structs Containing Structs?
Forward declarations of enumerations are non-standard (they violate C99 section 6.7.2.3 §3) and gcc will warn as well if you add the -pedantic
flag (which you should use if writing portable code).
The reason for this is that implementations are free to choose an integer type different from int
to use for representing the enumeration (see C99 section 6.7.2.2 §4). However, for that to work, the compiler has to see all values it needs to represent before an appropriate type can be chosen.
精彩评论