Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!dali.cs.montana.edu!rpi!uupsi!grebyn!ckp From: ckp@grebyn.com (Checkpoint Technologies) Newsgroups: comp.lang.c Subject: Re: Preprocessor macro to quote its argument Message-ID: <21594@grebyn.com> Date: 25 Aug 90 14:55:15 GMT References: <1112@mti.mti.com> <1114@mti.mti.com> <1990Aug20.012839.3545@zoo.toronto.edu> <11517@ogicse.ogi.edu> <1990Aug21.175138.24633@zoo.toronto.edu> Reply-To: ckp@grebyn.UUCP (Checkpoint Technologies) Organization: Grebyn Timesharing, Vienna, VA, USA Lines: 23 In article <1990Aug21.175138.24633@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: >The right way to fix the notorious `CTRL(D)' problem is to quote the D. >There is no portable way for the macro to supply the (single) quotes. >This has been true for a long time; tokenizing preprocessors existed >well before the ANSI C effort started. (This is just off the top of my head, so please be gentle...) Why can't this work? #define CTRL(ch) ((* #ch) - 64) It's ANSI only. The single # places it's arg in double quotes, making a string, and the * returns the first byte of the string. Now, I know this *could* be a constant expression. In ANSI, should a compiler treat this as a constant expression, which is allowed in static initializers etc? -- First comes the logo: C H E C K P O I N T T E C H N O L O G I E S / / \\ / / Then, the disclaimer: All expressed opinions are, indeed, opinions. \ / o Now for the witty part: I'm pink, therefore, I'm spam! \/