用gcc编译器隐式int和函数的隐式声明 [英] implicit int and implicit declaration of functions with gcc compiler

查看:166
本文介绍了用gcc编译器隐式int和函数的隐式声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c99 Standard中阅读:

I read in the c99 Standard:

-remove implicit function declaration,

-remove implicit int.

但是当我尝试使用-pedantic在c99模式下使用gcc编译器编译此代码时

But when I try to compile this code with gcc compiler in c99 mode using -pedantic

main(void){
    f(3);
    return 0;
}


int f(int a){
    ....
}

我预计会有2个错误,但我仅收到2条警告:

I expect 2 errors, but I just receive 2 warnings:

-warning: return type defaults to ‘int’

-warning: implicit declaration of function ‘f’.

它们不是c99中的错误吗?

Shouldn't them be errors in c99?

http://gcc.gnu.org/c99status.html
在两种情况都写为完成。

http://gcc.gnu.org/c99status.html In both situations there's written "done".

谢谢。

推荐答案

对于任何违反语法规则或约束的翻译单元,C标准都要求 diagnostic 。不需要这种诊断是致命的。编译器可以自由继续处理源文件。结果可执行文件的行为(如果有)是不确定的。该标准在警告和致命错误之间没有区别。

The C standard requires a diagnostic for any translation unit containing a violation of a syntax rule or constraint. It does not require such diagnostics to be fatal; the compiler is free to continue processing the source file. The behavior of the resulting executable, if any, is undefined. The standard makes no distinction between warnings and fatal errors.

需要的唯一编译器拒绝源文件是 #error 指令。)

(The only thing that requires a compiler to reject a source file is the #error directive.)

结论:编译C时,请非常小心警告。

Conclusion: when compiling C, take warnings very seriously.

这篇关于用gcc编译器隐式int和函数的隐式声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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