Undefined functions in C

Ian Lance Taylor ian@airs.com
Tue Feb 8 08:31:00 GMT 2005


Ian Wienand <ianw@gelato.unsw.edu.au> writes:

> > As you note, gcc in c99 mode will always give a warning for an
> > undeclared function; this is not true in c89 mode.  In c99 mode, the
> > compiler will give an error if you use the -pedantic-errors option.
> > Or the -Werror-implicit-function-declaration option.  Or the -Werror
> > option.
> 
> So do you know why if it is against the standard, gcc in with
> --std=c99 requires it be explicitly turned into an error?  Is it just
> a backwards/cross compatibility thing?

I haven't bothered to track down the patch which introduced this, but
I would speculate that 1) it will be desirable to eventually switch
gcc to default to c99 mode, but 2) it will not be desirable to break
lots of existing code at that time.  Given traditional C usage,
requiring a function declaration can be reasonably viewed as a
pedantic requirement, appropriate for -pedantic-errors.  In general,
if you want gcc to enforce strict adherence to the relevant standard,
you must use -pedantic-errors.

Of course there is a very reasonable coding style in which functions
should always be declared for use.  For that coding style, there is
-Werror-implicit-function-declaration.

Ian



More information about the Gcc-help mailing list