静态声明如下非静态声明 [英] static declaration follows non-static declaration

查看:540
本文介绍了静态声明如下非静态声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译与不同版本的CC的两个不同的机器相同的C文件。

I'm trying to compile the same C file on two different machines with different versions of cc.

gcc版本3.2.3说警告:'富'被宣布含蓄'的extern后来静态

gcc version 3.2.3 says warning: 'foo' was declared implicitly 'extern' and later 'static'

gcc版本4.1.2说错误:的'富'静态声明如下非静态声明

gcc version 4.1.2 says error: static declaration of 'foo' follows non-static declaration

AFAICT,都具有相同的CFLAGS。我想使GCC 4.1.2的行为很像GCC 3.2.3,也就是发现,会变成这个错误变成一个单纯的警告的选项。

AFAICT, both have the same CFLAGS. I'd like to make gcc 4.1.2 behave like gcc 3.2.3, that is, find an option that would turn this error into a mere warning.

推荐答案

大约从错误信息抱怨什么,这听起来像你倒是应该尝试修复源$ C ​​$ C。编译器抱怨在声明差异,类似实例

From what the error message complains about, it sounds like you should rather try to fix the source code. The compiler complains about difference in declaration, similar to for instance

void foo(int i);
...
void foo(double d) {
    ...
}

这是无效的C code,因此编译器会抱怨。

and this is not valid C code, hence the compiler complains.

也许你的问题是,有没有可用的原型功能时第一次使用,编译器隐式创建一个不会是静态的。如果是这样的解决方案是增加首次使用前某处它的原型。

Maybe your problem is that there is no prototype available when the function is used the first time and the compiler implicitly creates one that will not be static. If so the solution is to add a prototype somewhere before it is first used.

这篇关于静态声明如下非静态声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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