This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Undefined functions in C
- From: Ian Lance Taylor <ian at airs dot com>
- To: ianw at gelato dot unsw dot edu dot au
- Cc: gcc-help at gcc dot gnu dot org
- Date: 06 Feb 2005 21:52:50 -0500
- Subject: Re: Undefined functions in C
- References: <20050204045304.GC19233@cse.unsw.EDU.AU>
Ian Wienand <ianw@gelato.unsw.edu.au> writes:
> Googling around, you will find many people saying that C99 disallows
> undefined functions (e.g [1]), often citing C99 6.5.2.2. My reading
> of this doesn't seem to suggest it disallows undefined functions; in
> fact it talks about type promotion rules for undefined functions.
I don't see that. I see type promotion rules for functions declared
without a prototype, but that is not the same as functions which are
not declared at all.
> Can anyone point me to where C99 explicitly disallows a function
> without a declaration, and if so why doesn't gcc in C99 mode give an
> error rather than falling back to the C89 semantics? Or are the
> numerous people suggesting C99 disallows undefined functions
> incorrect?
C99 disallows a function without a declaration in 6.5.2.2 paragraph 1:
"The expression that denotes the called function shall have type
pointer to function returning void or returning an object type other
than an array type." This does not permit an undeclared symbol.
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.
Ian