LCC: Forward Declaration of Typedef'd Enum Failing?

坚强是说给别人听的谎言 提交于 2019-12-10 16:32:11

问题


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 wondering 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?


回答1:


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.



来源:https://stackoverflow.com/questions/7273535/lcc-forward-declaration-of-typedefd-enum-failing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!