C-Debug package ... (a la "context-independent macros")

Brandon Allbery bsa at ncoast.UUCP
Tue Feb 12 01:46:38 AEST 1985


> Article <1924 at wateng.UUCP>, from ksbszabo at wateng.UUCP (Kevin Szabo)
+----------------
| In article <33 at daisy.UUCP> pkl at daisy.UUCP (Peter K. Lee) writes:
| >	# define macro(args)\
| >		if (1) {\
| >			/* macro body */\
| >		}\
| >		else
| 
| I am also not going to use Peter's suggestion because it too can cause
| un-obvious behavior, but this time if the user makes a small syntax
| error. Suppose I forget the semicolon when I call the macro?
| ...
| I also find the macro definition hard to read...whenever I see an
| `else' I expect it to be controlling something. Very confusing.

The answer was posted about 3 months ago.

#define macro(args)\
	do\
	    {\
	    /* macro body */\
	    }\
	    while (0)

The body is executed exactly once, since the condition isn't found to
b false until the end... and a missing semicolon will show up as a syntax
error, which is reasonable.

Brandon (bsa at ncoast.UUCP)
-- 
Brandon Allbery, decvax!cwruecmp!ncoast!bsa, "ncoast!bsa"@case.csnet (etc.)
6504 Chestnut Road, Independence, Ohio 44131 +1 216 524 1416 (or what have you)



More information about the Comp.lang.c mailing list