This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c/6968: functions that shouldn't accept arguments accept infinitearguments (eg; test() )
- From: Terry Moreland <tmorelan at q dot cis dot uoguelph dot ca>
- To: zack at gcc dot gnu dot org, <gcc-bugs at gcc dot gnu dot org>, <gcc-prs at gcc dot gnu dot org>, <nobody at gcc dot gnu dot org>, <gcc-gnats at gcc dot gnu dot org>
- Date: Sat, 8 Jun 2002 02:44:36 -0400 (EDT)
- Subject: Re: c/6968: functions that shouldn't accept arguments accept infinitearguments (eg; test() )
I might be reading this wrong but does not:
An identifier list declares only the identifiers of the parameters of the function. An empty
list in a function declarator that is part of a definition of that function specifies that the
function has no parameters. The empty list in a function declarator that is not part of a
definition of that function specifies that no information about the number or types of the
parameters is supplied.124)
( ISO 9899:1999 Section 6.7.5.3 Paragraph 14 )
mean that in c99 void test() is a function that takes no arguments since
enmpty identifier list is part of the function definition and as such the
void test() example should produce an error in c99, but doesn't in gcc 3.1 using
-std=c99
please let me know if I am wrong, I have slept in a while and the iso c99 spec
can be very wordy at times
the reference 124 leads to 6.11.6 which mentions:
The use of function declarators with empty parentheses (not prototype-format parameter
type declarators) is an obsolescent feature.
Terry
On 8 Jun 2002 zack@gcc.gnu.org wrote:
> Synopsis: functions that shouldn't accept arguments accept infinite arguments (eg; test() )
>
> State-Changed-From-To: open->closed
> State-Changed-By: zack
> State-Changed-When: Fri Jun 7 22:56:53 2002
> State-Changed-Why:
> This is not a bug. The C standard specifies that a
> function declared with an empty parameter list (such
> as your void test ( ) ) accepts an indefinite number
> of arguments, not zero arguments. You must write
> void test ( void ) if you want to declare a function
> accepting zero arguments.
>
> (You may have C confused with C++. In C++ the rule
> is as you expected.)
>
> http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6968
>
--
--------------------------------------------------------
Terry Moreland | Computer and Information Science
tmorelan@uoguelph.ca | University of Guelph
If you were plowing a field, which would you rather use?
Two strong oxen or 1024 chickens?
- Seymour Cray (1925-1996), father of supercomputing
--------------------------------------------------------