4

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.

3
  • Believe it is just deprecated not removed. Commented Jun 23, 2012 at 16:32
  • @Als: No, C99 removed it altogether. Commented Jun 23, 2012 at 16:52
  • 1
    -pedantic just means be pedantic in telling the user. If you want the compiler to stop compilation on encountering such things, use -pedantic-errors. However, -Werror may be even better (in conjunction with -Wall -Wextra), since even warnings not required by the standard are undesirable. Commented Jun 23, 2012 at 17:49

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

Comments

4

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

Comments

4

Two points: first, it may (usually does) take a specific set of flags to get a compiler to conform with the standard.

Second, all that's required by the standard is that the implementation issue a "diagnostic" in the case of an error -- but it's up to the implementation to define what is or isn't a diagnostic. It's free to say a "warning" is a diagnostic if it wants to. When a diagnostic is issued, it may quit compiling, or it can compile the code anyway.

Bottom line: what it's doing is probably enough to conform, for whatever that's worth.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.