Defect Report #094
Submission Date: 03 Dec 93
Source: Ron Guilmette
ANSI/ISO C Defect report #rfg1:
There appears to be an inconsistency between the constraints on ``passing''
values versus ``returning'' values. The constraints for function
calls clearly indicate that a diagnostic is required if any given
actual argument is passed (to a prototyped function) into a corresponding
formal parameter whose type is not assignment compatible with respect
to the type of the passed value. In the case of values returned by
a return statement however, there seems to be no such compatibility
constraint imposed upon the expression given
in the return statement
and the corresponding (declared) function return type.
A new constraint should be added to the C Standard like:
If present, the expression given in a return statement
shall have a type such that its value may be assigned to an object
with the unqualified version of the return type of the containing
(This exactly mirrors the existing constraint on parameter matching
imposed upon calls to prototyped functions.)
The constraint in the description of the return statement is
unneeded. Early on, the Committee decided that if a behavior was described
as being equivalent to another construct, all of the constraints of
that construct would apply. This ``chaining'' process means
that any violation of a constraint in any section referred to explicitly
or by the phrases ``equivalent behavior'' or ``as if''
will generate a diagnostic.
The Semantics section of the return statement (subclause 188.8.131.52)
states: ``If the expression has a type different from that of the
function in which it appears, it is converted as if it were assigned
to an object of that type.'' The constraints in the section on
simple assignment (subclause 184.108.40.206) are sufficient to assure assignment
compatibility of the two types.
Previous Defect Report
< - >
Next Defect Report