C pre-processor and ANSI standard

Chris Torek chris at umcp-cs.UUCP
Mon Sep 10 08:46:15 AEST 1984


I always parenthesize my min/max #define's.  The big problem with those
is that they still generate side effects twice.  (But hey!, that's what
macros are all about!)

As for a macro to put out N spaces, how about:

#define spaces(n) \
	if (1) { \
		register int _youwouldntusethisid = (n); \
		while (--_youwouldntusethisid >= 0) \
			putchar(' '); \
	} \
	else

This gets around the

	if (expr)
		spaces(expr);
	else
		...

(dangling else) problem.  Now your only trap is writing

	foo()
	{
		spaces(6)
		bar();
	}

(a missing semicolon makes unreachable code).

Unfortunately, this gives lint indigestion (``constant in conditional
context'').
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci (301) 454-7690
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.lang.c mailing list