Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!pyramid!pesnta!wjvax!brett From: brett@wjvax.UUCP (Brett Galloway) Newsgroups: net.lang.c,net.bugs Subject: Re: e1?(void_e2):(void_e3) so, is it legal or what? Message-ID: <751@wjvax.wjvax.UUCP> Date: Tue, 19-Aug-86 12:17:19 EDT Article-I.D.: wjvax.751 Posted: Tue Aug 19 12:17:19 1986 Date-Received: Thu, 21-Aug-86 04:10:46 EDT References: <518@hadron.UUCP> <243@desint.UUCP> <745@wjvax.wjvax.UUCP> <248@desint.UUCP> Reply-To: brett@wjvax.UUCP (Brett Galloway) Organization: Watkins-Johnson Co., San Jose, Calif. Lines: 35 Xref: mnetor net.lang.c:5698 net.bugs:328 In article <248@desint.UUCP> geoff@desint.UUCP (Geoff Kuenning) writes: >In article <745@wjvax.wjvax.UUCP> brett@wjvax.UUCP (Brett Galloway) writes: > >> You are correct, but this is true of ALL uses of '?:`. In fact, '?:` is >> VERY useful, especially when you want to embed conditionals in a macro. >> Using the if() {} else {} form restricts the contexts in which the macro >> may appear. > >Unfortunately, Brett is incorrect here. You can't use if/then/else to write: > > for (i = up ? 0 : 99; up ? (i < 100) : (i >= 0); up ? i++ : i--) > { > /* complex loop body */ > } > I thought I said the same thing -- '?:` is useful in some cases where if/then/else isn't. >without duplicating code. On the other hand, anywhere you want do >if/then/else (or any other complex statement, such as loops and switches) >inside a macro without restricting where the code can be used, you can >just write: > > #define abc(x) do { \ > /* anything you want goes here, even declarations */ \ > } while (0) I don't think this method is general. For example, your macro abc() cannot be used inside a for() construct. -- ------------- Brett Galloway {pesnta,twg,ios,qubix,turtlevax,tymix,vecpyr,certes,isi}!wjvax!brett