Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!nike!cit-vax!elroy!smeagol!usc-oberon!sdcrdcf!trwrb!desint!geoff From: geoff@desint.UUCP (Geoff Kuenning) Newsgroups: net.lang.c,net.bugs Subject: Re: e1?(void_e2):(void_e3) so, is it legal or what? Message-ID: <248@desint.UUCP> Date: Sat, 16-Aug-86 16:09:38 EDT Article-I.D.: desint.248 Posted: Sat Aug 16 16:09:38 1986 Date-Received: Mon, 18-Aug-86 00:51:47 EDT References: <518@hadron.UUCP> <243@desint.UUCP> <745@wjvax.wjvax.UUCP> Reply-To: geoff@desint.UUCP (Geoff Kuenning) Organization: SAH Consulting, Manhattan Beach, CA Lines: 37 Xref: watmath net.lang.c:10271 net.bugs:876 In article <745@wjvax.wjvax.UUCP> brett@wjvax.UUCP (Brett Galloway) writes: > In article <243@desint.UUCP> geoff@desint.UUCP (Geoff Kuenning) writes: >>let us not forget that there >>is *no* reason to ever write this particular expression. > 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 */ } 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) and almost all compilers will optimize the loop out completely (something that very few optimizers could do with the "complex loop body" above, especially because it trades time off for space and few compiler writers are willing to make that decision). I learned this method from in net.lang.c. -- Geoff Kuenning {hplabs,ihnp4}!trwrb!desint!geoff