Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!nike!sri-spam!parcvax!hplabs!tektronix!uw-beaver!uw-june!entropy!dataio!bright From: bright@dataio.UUCP (Walter Bright) Newsgroups: net.lang.c,net.bugs Subject: Re: e1?(void_e2):(void_e3) so, is it legal or what? Message-ID: <1061@dataio.UUCP> Date: Wed, 13-Aug-86 12:29:57 EDT Article-I.D.: dataio.1061 Posted: Wed Aug 13 12:29:57 1986 Date-Received: Thu, 14-Aug-86 22:01:14 EDT References: <155@cbnap.UUCP> <499@dg_rtp.UUCP> <518@hadron.UUCP> <243@desint.UUCP> Reply-To: bright@dataio.UUCP (Walter Bright Organization: Data I/O Corp., Redmond WA Lines: 46 Xref: mnetor net.lang.c:5635 net.bugs:319 In article <243@desint.UUCP> geoff@desint.UUCP (Geoff Kuenning) writes: >While all of this discussion is very interesting and is important to >achieving a precise language definition, let us not forget that there >is *no* reason to ever write this particular expression. Anywhere it's >useful, you can just write > > if (e1) > void_e2; > else > void_e3; Not quite. This type of expression is very useful for macros which must in themselves be expressions (to avoid peculiar {} and ; problems). Such as: #define biff(pow) ((pow) ? kayo() : oof()) Defining the macro as: #define biff(pow) if (pow) kayo(); else oof(); causes difficulties with constructs like: if (socko) biff(flez); else bang(glurp); Similar problems exist for the other permutations of defining biff(). Now for the RIGHT (!) definition of when a void expressions is valid: A void expression is valid only under circumstances where the value of an expression is not used. This means that: (a ? voidexp : voidexp),(a=b) is valid. But a=a?voidexp:voidexp isn't valid, as the value is used. Apply the rule above to all the cases and you have the RIGHT (!) answer. Note that by implication, if the value of the ?: expression is not used, the operands of the : need not be of compatible types, and need not be brought to a common type. I would like to see the ANSI C spec clarified on this point.