如何解决GCC C代码中的非静态声明之后的静态声明? [英] How to solve static declaration follows non-static declaration in GCC C code?

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

问题描述

我正在尝试在具有不同cc版本的两台不同计算机上编译相同的C文件.

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

gcc版本3.2.3说warning: 'foo' was declared implicitly 'extern' and later 'static'

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

gcc版本4.1.2表示error: static declaration of 'foo' follows non-static declaration

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

两者都具有相同的CFLAGS.我想让gcc 4.1.2表现得像gcc 3.2.3一样,也就是说,找到一个选项,可以将这个错误变成纯粹的警告.

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.

推荐答案

从错误消息所抱怨的内容来看,听起来您应该宁愿尝试修复源代码.编译器抱怨声明的差异,类似于例如

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代码,因此编译器会抱怨.

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.

这篇关于如何解决GCC C代码中的非静态声明之后的静态声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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