GCC 标准编译规则的发行版/版本与另一版本不同:结构
前一段时间,我使用的是在 Windows 下运行的 Dev C++ IDE,带有 MinGW(GCC 的 Windows 端口),现在我转移到 MAC OS X Leopard,我正在使用 Code::Blocks IDE 和 GCC v4.2(苹果修改)版本)随 XCode 3.2.2 一起提供。我不知道我的问题是否取决于发行版(Dev cpp)或编译器版本,或者可能是它是 GCC 的 Apple 发行版这一事实,但我在声明结构化数据时遇到了这种差异。
在旧的 Dev CPP 中,在 Windows 上运行时,我只是简单地声明了这个
const int max = 1000;
struct data{
char thing[max];
int anotherthing;
}
然后我将它引用到这样的函数:
void some_function(data some)
它运行良好。在使用 Code::Blocks IDE 的 Xcode 版本编译器上,我收到一些错误,并且无法编译。
new types may not be defined in a return type
错误:“max”未在此范围内声明
谢谢!
Some time ago i was using a Dev C++ IDE which runs under Windows and comes with MinGW (Windows port of GCC), now i moved to MAC OS X Leopard and I am using Code::Blocks IDE with GCC v4.2(apple modified version) which comes with XCode 3.2.2. I don't know if my problem depends upon distribution (Dev cpp) or compilator release, or maybe the fact that it's an Apple distribution of GCC, but i encountred this diffrence in declaring structured data.
In old Dev CPP, running on Windows i simply delcared this
const int max = 1000;
struct data{
char thing[max];
int anotherthing;
}
then i used referencing it to a function like this:
void some_function(data something)
It worked well. On Xcode version of the compiler using Code::Blocks IDE i get some errors and it won't compile.
new types may not be defined in a return type
error: 'max' was not declared in this scope
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在其冷藏的右行发表了带有错误内容的评论。
包括
使用命名空间 std;
常量整数最大值 = 1000;
typedef 结构数据{
};
...然后是主函数:
int main(){
...继续执行好的代码
I maked a comment with error content on the right line which it reefers to.
include
using namespace std;
const int max = 1000;
typedef struct dato{
};
...Then comes the main function:
int main(){
...continue whit good code
从您发布的代码片段来看,我没有发现任何问题。它应该可以编译,而不会出现您遇到的错误。如果将 max 移入 main 的本地范围会发生什么? aArray 的错误仍然出现吗?
我能想到的唯一可能影响编译的事情是传递给 gcc 的开关。调用 gcc 时 C::B 传递的命令是什么样的?
From the code snippet you posted, I don't see anything wrong with it. It should compile without the error that you're getting. What happens if you move max into main's local scope? Does that error for aArray still come up?
The only other thing I could think of that might affect compilation are the switches passed to gcc. What does the command being passed by C::B look like when gcc is invoked?