e1?(void_e2):(void_e3) so, is it legal or what?

Daniel R. Levy levy at ttrdc.UUCP
Sun Aug 17 05:21:50 AEST 1986


In article <1061 at dataio.UUCP>, bright at dataio.UUCP (Walter Bright) writes:
>#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().

Presuming that

	void kayo(), oof();

is intended, whatsa matter with

#define biff(pow)	{ if (pow) kayo(); else oof(); }

This combines the if-else into one single statement.

There is a slight handicap that this doesn't work too well as the first
operand of the comma operator ("syntax error") but at least some common
modern C compilers (as on the SV 3B20) don't like Bright's macro either in
this context or for that matter in any other context
("operands of : have incompatible types").  O.K., Bright (and others) have
been saying "change the definition of C to allow this."  Well I say the same
thing about my suggestion, so THERE!  :-)
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
	   go for it!  			allegra,ulysses,vax135}!ttrdc!levy



More information about the Comp.lang.c mailing list