composite type example from C11 standard

S

stephenfsiegel

I'm confused about something in the C11 Standard. In Section 6.2.7 "Compatible type and composite type", item (4) states:

"For an identifier with internal or external linkage declared in a scope inwhich a prior declaration of that identifier is visible, if the prior declaration specifies internal or external linkage, the type of the identifier at the later declaration becomes the composite type."

Immediately after this, in item (5), the following example appears:

--- begin example ---
Given the following two file scope declarations:
int f(int (*)(), double (*)[3]);
int f(int (*)(char *), double (*)[]);
The resulting composite type for the function is:
int f(int (*)(char *), double (*)[3]);
--- end example ---

However, the second declaration of f occurs in a scope in which a prior declaration of f (namely, the first declaration) is visible, and both declarations specify external linkage (see Sec. 6.2.2, in particular "If the declaration of an identifier for a function has no storage-class specifier, its linkage is determined exactly as if it were declared with the storage-class specifier extern."). Therefore, according to (4), the composite type should be the type at the second declaration, not "int f(int (*)(char *), double(*)[3]);".

What am I missing?
Thanks.
 
S

stephenfsiegel

Never mind. I thought the sentence "... the type of the identifier at thelater declaration becomes the composite type." was defining the compositetype in that situation. Instead, it is defining the type of the identifier, relying on the definition of composite type given earlier.
 
B

Ben Bacarisse

I'm confused about something in the C11 Standard. In Section 6.2.7
"Compatible type and composite type", item (4) states:

"For an identifier with internal or external linkage declared in a
scope in which a prior declaration of that identifier is visible, if
the prior declaration specifies internal or external linkage, the type
of the identifier at the later declaration becomes the composite
type."

Immediately after this, in item (5), the following example appears:

--- begin example ---
Given the following two file scope declarations:
int f(int (*)(), double (*)[3]);
int f(int (*)(char *), double (*)[]);
The resulting composite type for the function is:
int f(int (*)(char *), double (*)[3]);
--- end example ---

However, the second declaration of f occurs in a scope in which a
prior declaration of f (namely, the first declaration) is visible, and
both declarations specify external linkage (see Sec. 6.2.2, in
particular "If the declaration of an identifier for a function has no
storage-class specifier, its linkage is determined exactly as if it
were declared with the storage-class specifier extern."). Therefore,
according to (4), the composite type should be the type at the second
declaration, not "int f(int (*)(char *), double (*)[3]);".

What am I missing?

Your last sentence does not say what 6.2.7 p4 says. It says that the
type of the identifier (f) becomes the composite type formed from the
two declarations. I.e. you've just got the words the wrong way round.
 

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