macros with parameters in MSC 5.0

Doug Gwyn gwyn at brl-smoke.ARPA
Mon Feb 22 13:09:25 AEST 1988


In article <4099 at hoptoad.uucp> gnu at hoptoad.uucp (John Gilmore) writes:
>jbaker at ee.UCLA.EDU (Joe Baker) wrote:
>> #define ctl(c) ('c'&037)
>This change caused us to have to fix more than 50 files in Berkeley
>Unix.  We wouldn't have minded changing all the macro definitions -- we
>know that substitution inside strings is a hack -- it's that we had to
>change all the CALLERS too that bugged us!
>[Responses of the form: "Well, you already fixed your code, so why should
>we make the standard reasonable?" are bogus.  A useful capability was removed,
>and replaced with a less capable set of features.]

First, this was NOT a change to the C language.  K&R already guaranteed
that macro substitution would not occur inside string and character
literals (section 12.1 of Appendix A).  I daresay there are more
instances of C compilers currently that do not do such substitution than
those that do; generally only compilers adapted from AT&T's source (the
Reiser C preprocessor in particular) have this bug.

X3J11, realizing that the facility was nevertheless useful, designed an
alternative approach that was compatible with the K&R definition.

To see what is wrong with the Reiser method, try the following program:

#include <stdio.h>
#define TEST(a,b) ((void)fprintf(stderr,"This is a test: 0x%x\n",(a)^(b)))
main()	{
	TEST(0xFF<<4,0xFFFF>>4);
	return 0;
	}



More information about the Comp.lang.c mailing list