Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

implicit int and implicit declaration of functions with gcc compiler

Tags:

c

c99

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.

like image 459
abc Avatar asked Dec 06 '22 13:12

abc


2 Answers

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.

like image 120
Keith Thompson Avatar answered Dec 29 '22 09:12

Keith Thompson


I don't believe the compiler is required to produce a fatal error. Use -Werror if you're concerned...

like image 41
Oliver Charlesworth Avatar answered Dec 29 '22 08:12

Oliver Charlesworth