Defect Report #157
Submission Date: 16 Oct 95
Submittor: BSI
Source: Clive D.W. Feather
Question
Submitted to BSI by Clive D.W. Feather clive@sco.com.
In this Defect Report, identifiers lexically identical to those
declared in standard headers refer to the identifiers declared in those
standard headers, whether or not the header is explicitly mentioned.
This Defect Report has been prepared with considerable help from
Mark Brader, Jutta Degener, Ronald Guilmette, and a person whose
employment conditions require anonymity. However, except where stated,
opinions expressed or implied should not be assumed to be those of any
person other than myself.
Defect Report UK 005: Legitimacy of type synonyms
The C Standard does not clearly indicate when the spelling of a
type name is or is not significant; in other words, when a type name
may be replaced by another type name representing the same type.
Part 1
Subclause 6.5.4.3 reads in part:
The special case of void as the only item in the
list specifies that the function has no parameters.
Subclause 6.7.1 reads in part:
(except in the special case of a parameter list consisting of a
single parameter of type void, in which there shall
not be an identifier).
In both cases, the word void is set in the
typeface used to indicate C code.
In the code:
typedef void Void;
extern int f (Void);
int f (Void) {
return 0; }
is the declaration on line 2 strictly conforming, and is the
external definition on line 3 strictly conforming?
Part 2
Subclause 5.1.2.2.1 reads in part: It can be defined with no
parameters:
int main (void) { /* ... */ }
Is the following definition of main strictly
conforming?
typedef int word;
word main (void) { /* ... */ }
Part 3
Are there any circumstances in which a typedef name is not
permitted instead of the type it is a synonym for? If so, what are
they?
Proposed Response
A synonym is always acceptable, except that a function definition
may not use a typedef for the function type.
Response
Part 1
Both function declarations are strictly conforming.
Subclause 6.7.1 makes clear that it is a single parameter having the
type void (as opposed to use of the void keyword) that indicates
that a function takes no parameters.
For clarity, Subclause 6.5.4.3 should be rephrased to emphasize
that it is the type void, not the keyword voidthat matters.
Future Change
In Subclause 6.5.4.3,
Change
"The special case of void as the only item in the list specifies that
the function has no parameters."
To
"The special case of an unnamed parameter of type void as the only item
in the list specifies that the function has no parameters."
Part 2
Yes, the definition of main is strictly conforming.
Part 3
A synonym is not acceptable in these cases:
- A function definition may not use a typedef for the function type:
typedef void F(void);
extern F g { } /* Invalid */
- A typedef may not be combined with another type specifier:
typedef int I;
short I x; /* Invalid */
Previous Defect Report
< - >
Next Defect Report