Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

c - implicit int and implicit declaration of functions with gcc compiler

I read in the c99 Standard:

-remove implicit function declaration,

-remove implicit int.

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

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

-warning: return type defaults to ‘int’

-warning: implicit declaration of function ‘f’.

Shouldn't them be errors in c99?

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

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

Conclusion: when compiling C, take warnings very seriously.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...