e1?(void_e2):(void_e3) so, is it legal or what?
Joseph S. D. Yao
jsdy at hadron.UUCP
Sun Aug 10 15:01:21 AEST 1986
In article <499 at dg_rtp.UUCP> throopw at dg_rtp.UUCP (Wayne Throop) writes:
>Any clod can have facts, but having opinions is an art.
>> whp at cbnap.UUCP (W. H. Pollock x4575 3S235)
>>> jcz at sas.UUCP (Carl Zeigler)
>>>Scan again, Andrew, the (void) values are being thrown away.
>> The void values are not thrown away! Remember that (A?B:C) is an
>> expression *returning a value*.
[paraphrase -j-]
>K&R don't say anything, since no (void) back then.
>Harbison and Steele say:
> 3. They [the second and third subexpressions] may have identical
> types (structure, union, enumeration, or void). The result is of
> this same type.
>ANSI C draft standard, C.3.15.
> The first operand shall have scalar type. Both the second and third
> operands shall have arithmetic type, or shall have the same
> structure, union, or pointer type, or shall be void expressions. In
> addition, one may be an object pointer and the other a pointer to
> void, or one may be a pointer and the other a null pointer constant.
> ...
> If both the operands are void expressions, the result is a void
> expression.
>All fairly clear and straightforward. It is legal.
*sigh* OK, let's get this straight. PROPOSED ANSI standard
X3J11 describes a language (set of languages, over the past
few years) that has (and have) not yet been implemented any-
where by anyone (or if they have, word hasn't gotten to this
corner yet). H&S, while a very good book, does take some
liberties at interpretation. They are on the ANSI X3J11
committee, and could have been influenced in their interpre-
tations by the committees deliberations. Most compilers
today follow K&R, which by declaring that the conditional
expression has (1) a result (2) with a data type predicated
on the types of the operands, seems to be prohibiting use
of void-type objects. Until recently, Proposed X3J11
concurred with this, specifically allowing only arith types,
structures, unions, and pointers of the same type (remembering
that "0" can be construed as a pointer of any type).
Bottom line: it's a mite early to be pointing to Proposed
X3J11 and saying something is "right" or "not right" based
on that. Agreed, we should all follow and be aware (as I
was not, of this) of things affecting our good programming
practice. As of now, the standards are K&R with s3 and s5
enhancements. Anything that is not explicitly defined in
one of these is subject to interpretation. As H&S points
out, the C language is what the C compiler accepts.
--
Joe Yao hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}
jsdy at hadron.COM (not yet domainised)
More information about the Net.bugs
mailing list