Article View: comp.std.c
Article #4788Re: Is a diagnostic required?
From: Tanmoy Bhattacharya
Date: Fri, 23 Feb 1996 01:00
Date: Fri, 23 Feb 1996 01:00
77 lines
3599 bytes
3599 bytes
Path: newshost.lanl.gov!ferrari.mst6.lanl.gov!tesuque.cs.sandia.gov!sloth.swcp.com!ns2.mainstreet.net!bug.rahul.net!rahul.net!a2i!genmagic!sgigate.sgi.com!wrdis02.robins.af.mil!rcp6.elan.af.mil!rscernix!danpop
From: danpop@mail.cern.ch (Dan Pop)
Newsgroups: comp.std.c
Subject: Is a diagnostic required?
Date: 22 Feb 96 14:35:40 GMT
Organization: CERN European Lab for Particle Physics
Lines: 27
Message-ID: <danpop.824999740@rscernix>
NNTP-Posting-Host: ues5.cern.ch
X-Newsreader: NN version 6.5.0 #7 (NOV)
In article <danpop.824999740@rscernix>
danpop@mail.cern.ch (Dan Pop) writes:
DP: Hi,
DP:
DP: Does the following code require a diagnostic?
DP:
DP: foo()
DP: {
DP: }
DP:
DP: main()
DP: {
DP: foo(3);
DP: }
DP:
No.
DP: I was always convinced that there is no difference between foo() and
DP: foo(void) in the _definition_ of the function foo and that 'void' as the
DP: argument list of a function was introduced for function declarations,
DP: because an empty argument list in a function declaration had to be
DP: treated as in K&R C. Yet, all the compilers I tried accepted this code
DP: without complaint and complained when 'void' was introduced in the
DP: definition of foo.
6.5.4.3 shows
D (parameter-type-list)
or
D (identifier-list_opt)
Note that the parameter-type-list is not optional.
Now, there is a special case for empty identifier-list_opt in
definition of a function for the purposes of determining type
compatibililty. Thus an `int foo(int)' declaration in your above
program would lead to a diagnostic being required.
6.7.1 clarifies that only functions defined with parameter-type-lists
acquire a prototype. Of course, `only' means no other clause leads to
a prototyped function: which is ridiculous because this clause is
talking about function definitions only. However, the usage in 6.5.4.3
`If one type has a parameter type list and the other type is specified
by a function definition that contains a (possibly empty) identifier
list, both shall agree in the number of parameters and the type of
each prototype parameter shall be compatible with the type that
results from the application of the default argument promotions to the
type of the corresponding identifier' seems to argue that when a
declaration specifies a parameter-type-list, it is a prototype. Why
didn't the standard make this explicit anyway by a statement in
6.5.4.3? Or does it actually mention it somewhere else?
In any case, the intent is clear: and as 6.3.2.2 constraint applies
only to prototyped function, no diagnostic is required.
Cheers
Tanmoy
--
tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
Technical Details
Message-ID:
<TANMOY.96Feb22180046@qcd.lanl.gov>Path:
arc1-ca.pugleaf.net!newshost.lanl.gov!tanmoyReferences:
<danpop.824999740@rscernix>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newshost.lanl.gov!tanmoy From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya) Newsgroups: comp.std.c Subject: Re: Is a diagnostic required? Date: 23 Feb 1996 01:00:46 GMT Organization: Los Alamos National Laboratory Message-ID: <TANMOY.96Feb22180046@qcd.lanl.gov> References: <danpop.824999740@rscernix> NNTP-Posting-Host: qcd.lanl.gov Mime-Version: 1.0 Content-Type: text In-reply-to: danpop@mail.cern.ch's message of 22 Feb 96 14:35:40 GMT