Strange function use

  • Thread starter Christian Christmann
  • Start date
E

ena8t8si

Eric said:
Eric Sosman wrote:




So the return type is not part of the prototype ?
Why not ?

"Why not?" Because of 6.9.1/7:

"The declarator in a function definition specifies the
name of the function being defined and the identifiers
of its parametsrs. [Note omission of return type.] If
the declarator includes a parameter type list, [...]
such a declarator also serves as a function prototype
for later calls to the same function [...]"

Despite the return type not being mentioned, a function's return
type can't be completely divorced from its declarator:

int fee(int), *fie(int), **foe(int), ***fum(int);

To me it makes just as much sense to say a declarator does
specify its return type, at least implicitly by virtue of
what type specifiers it comes after.
Since the declarator "serves as a function prototype" even though
it does not include the function's return type, a prototype does
not include the return type.

... and yet, there seem to be contradictions. 6.2.1/2:

"[...] (A _function prototype_ is a declaration of
a function that declares the types of its parameters.)"

A function declaraTION (not declaraTOR) *does* include the return
type, so this passage says you're right and I'm wrong. Hard to
say which paragraph wins out.

But then there's 6.7.5.3/1:

"A function declarator shall not specify a return type
that is a function type or an array type."

... implying that a declaraTOR does incorporate the return type
(or the constraint would be vacuous). I think this must be a
typo for declaraTION, because the grammar of 6.7/1 shows that
the return type is part of the declaration-specifiers, separate
from the init-declarator-list that eventually contains the
declarator.

Actually only part of the return type is in the declaration
specifiers:

int foo()[4]; /* yes this isn't legal */

The int-ness is in the declaration specifiers; the
array-sub-4-ness is in the declarator.
Hence, according to the grammar the function's
return type is not part of the declaraTOR, but is part of the
declaraTION.

Here's my guess for the source of the confusion. A
declarator is too small, a declaration is too big.
In the declaration

int blah(int z(void));
-----------
---------------------

there are supposed to be two prototypes (underlined).
The problem is what to say about z: if that's really
the prototype, it's bigger than a declarator, but not
as big as a whole declaration.

The easiest way to make sense of it all is to read the
word "declaration" in 6.2.1/2 as being used informally
rather than in its technically defined sense.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top