macros with parameters in MSC 5.0

Karl Heuer karl at haddock.ISC.COM
Sat Feb 20 04:01:49 AEST 1988


In article <7277 at brl-smoke.ARPA> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>In article <11879 at brl-adm.ARPA> jbaker at ee.UCLA.EDU (Joe Baker) writes:
>>#define ctl(c) ('c'&037)
>
>Yes, whoever did this was deliberately violating the K&R rules

I looked it up when I first saw this hack, and I concluded that K&R didn't
establish an unambiguous rule.  The book says that macros are not expanded
inside strings, but I don't think it specifies whether macro *arguments* are
expanded inside strings within the macro.

>With ANSI C, or any C preprocessor that includes the stringizing
>feature, you can make the original usage work by
>	#define ctl(c) (#c[0]&037)
>which would cause
>	case ctl(G):
>to expand to
>	case ("G"[0]&037):

Umm, I believe that according to the C rules, that's a non-constant expression
(and hence illegal as a case label).

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list