What is a constant expression
David Goodenough
dg at lakart.UUCP
Sat Oct 21 03:46:23 AEST 1989
>From article <1219 at crdos1.crd.ge.COM>, by davidsen at crdos1.crd.ge.COM (Wm E Davidsen Jr):
> Background: large program, defines ASCII control characters with a
> macro as follows:
> #define CNTL(c) ('c' & 037)
> While this work fine with pcc, the ANSI preprocessor doesn't expand it.
This is:
1. Grotesque,
2. Workable.
Flame away if you wish, just try it first.
#define prequote(x) 'x
#define postquote(x) x'
#define CNTL(c) ((postquote(prequote(c))) & 0x1f)
CNTL(c)
Bletch :-/
MAJOR MAJOR PROBLEM - our C compiler (greenhills) likes the useages of
postquote and prequote in that order. Some compilers may not care, while
others might want them reversed. I think it depends on whether nested
macros are expanded from the inside out (as Greenhills does), or outside
in.
It's probably not portable .... Oh well.
--
dg at lakart.UUCP - David Goodenough +---+
IHS | +-+-+
....... !harvard!xait!lakart!dg +-+-+ |
AKA: dg%lakart.uucp at xait.xerox.com +---+
More information about the Comp.std.c
mailing list