[PATCH] Fix PR c/6326

Joseph S. Myers jsm28@cam.ac.uk
Wed May 1 12:52:00 GMT 2002


On Wed, 1 May 2002, Eric Botcazou wrote:

>     PR c/6326
>     * c-decl.c (grokparms): turn an empty parameter
>     list into a (void) list in a function definition
>     if speaking ISO C99.

This (and the PR) is wrong - obviously wrong once you properly understand
how prototyped and nonprototyped function types work in C (which is
straighforward - perhaps not the most obvious or natural design if one
were to design from scratch, but nonprototyped functions are deprecated in
the standard).  Please read the standard.  "specifies that the function
has no parameters" does not mean "declares the identifier has having a
type that includes a prototype".  The arguments in a function call are
only checked (6.5.2.2#2,#8) if the called function has a type that
includes a prototype.  In particular read 6.5.2.2#8:

       [#8] No  other  conversions  are  performed  implicitly;  in
       particular,  the  number  and  types  of  arguments  are not
       compared  with  those  of  the  parameters  in  a   function
       definition  that  does  not  include  a  function  prototype
       declarator.

There is no such thing as an empty parameter list.  The syntax in 6.7.5#1
clearly shows that a parameter-list must contain at least one
parameter-declaration.  The empty parentheses are, rather, the omission of
an optional identifier-list; it is not a prototype.  The function
definition serves as a prototype iff it contains a parameter type list
(6.9.1#7).

Of course we could give warnings (not errors) for such a case anyway, even
though not required by the standard - but the manual explains why we don't
in this case.

-- 
Joseph S. Myers
jsm28@cam.ac.uk



More information about the Gcc-patches mailing list