ctl(c) macro

Mark Brader msb at sq.uucp
Sun Feb 21 10:42:15 AEST 1988


> #define ctl(c) ('c'&037)

This is a well-known nonportability.  Substitution within string and
character constants was a feature of certain versions of the C compiler
(including many UNIX versions) that was documented only in the README
file in the source directory for the compiler!  If it had been generally
announced, e.g. in K&R, it might have made it into the ANSI standard,
but as it never was announced, it is best considered a common *bug*.
There are arguments in favor of it and against it.

The stringizing operator was the ANSI subcommittee's invention, a different
way to get that functionality, but it is also nonportable to most existing
systems.

> I have come up with some ugly fixes, but would like to know: what is
> the Right Way to do this?

Don't turn what looks like a variable (namely c) into a constant.  Say

	#define CTL(c) ((c) & 037)

and use
	CTL('c')

Okay?
Mark Brader, SoftQuad Inc., Toronto, utzoo!sq!msb, msb at sq.com
#define	MSB(type)	(~(((unsigned type)-1)>>1))



More information about the Comp.lang.c mailing list