Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!nike!think!husc6!harvard!panda!genrad!decvax!mcnc!rti-sel!dg_rtp!throopw From: throopw@dg_rtp.UUCP (Wayne Throop) Newsgroups: net.lang.c,net.bugs Subject: e1?(void_e2):(void_e3) so, is it legal or what? Message-ID: <499@dg_rtp.UUCP> Date: Mon, 4-Aug-86 13:58:43 EDT Article-I.D.: dg_rtp.499 Posted: Mon Aug 4 13:58:43 1986 Date-Received: Tue, 5-Aug-86 22:43:16 EDT References: <273@watmath.UUCP> <5858@alice.uUCp> <134@sas.UUCP> <155@cbnap.UUCP> Lines: 46 Summary: Look it up in Holy Writ! Xref: mnetor net.lang.c:5558 net.bugs:308 > whp@cbnap.UUCP (W. H. Pollock x4575 3S235) >> jcz@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*. Uh, well, no actually. I'll join in this tis-so/tis-not debate using the radical approach of seeing what fairly-well-respected references have to say on the subject. First, note that K&R don't say anything about it, since they didn't have (void) back then. Second, Harbison and Steele say that ?: expressions come in four flavors. One flavor is interesting here (from page 183): 3. They [the second and third subexpressions] may have identical types (structure, union, enumeration, or void). The result is of this same type. Third, the 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. So, the objection: > C is giving the error because it can't > determine the type of the return value. is incorrect. The "type" returned from a ?: expression with void trailing operands is void. -- Any clod can have facts, but having opinions is an art. --- Charles McCabe, San Francisco Chronicle -- Wayne Throop !mcnc!rti-sel!dg_rtp!throopw