LCC:typedef定义枚举的向前声明失败? [英] LCC: Forward Declaration of Typedef'd Enum Failing?

查看:189
本文介绍了LCC:typedef定义枚举的向前声明失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下code段编译就好了Mac OS X上使用gcc,但未能在Windows编译LCC-win32的:

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 };

和给出了这样的错误:

未知枚举'富'

在我的具体情况,这不是一个问题。我简单的语句组合成:

In my particular case, this was not a problem. I simply combined the statements into:

typedef enum Foo { Bar = 1 } Foo;

但我不知道是否LCC正在或者更为严格(遵守一些标准)或哑口(编译器是太愚蠢来处理这种情况)。

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).

感谢。

此外,请参阅我的其他LCC的问题: LCC:初始化结构体结构体含

Also, please see my other LCC question: LCC: Initializing Structs Containing Structs?

推荐答案

枚举的正向声明是非标准(它们违反C99部分6.7.2.3§3),如果你添加<$ C $ gcc会发出警告,以及C> -pedantic 标志(你应该使用如果写入便携式code)。

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).

这样做的原因是,实现可以自由选择从 INT 不同的整数类型用于再presenting枚举(见C99 6.7.2.2节§4)。然而,对于工作,编译器,看看它需要重新present可以选择合适的类型之前的所有值。

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.

这篇关于LCC:typedef定义枚举的向前声明失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆