Path: utzoo!attcan!uunet!peregrine!ccicpg!felix!dhw68k!feedme!doug From: doug@feedme.UUCP (Doug Salot) Newsgroups: comp.lang.c Subject: ANSIfication of #define ctl(X) ('X' & 0x1f) Message-ID: <37@feedme.UUCP> Date: 11 Jun 88 00:50:12 GMT Organization: Feedme Microsystems, Orange County, CA Lines: 27 No doubt this has been hashed out before (if so, email from the solution poster would be appreciated), but what is the accepted method of porting macro substitution within character constants to dpANS-conforming compilers? A method which immediately suggests itself (to a warped mind) for the control character macro in the subject heading is #define ctl(X) (#X [0] & 0x1f) which does the trick, but has (at least) two problems. First, and less worrisome for q&d ports, is that a couple of bytes are added to the string table for each invocation. Worse is the sad fact that most compilers treat "xyz"[0] as a non-constant runtime expression and disallow the macro expansion in case statements (where I happen to need it). Question to satisfy curiosity: is it obvious that a constant string indexed by a constant isn't a constant? Clearly, this is an exceptional case of string indexing, but it should be safe to evaluate the expression to a constant character at compile-time, shouldn't it? More importantly, is there a way to do what I want to do without changing the macro invocations? -- Doug Salot || doug@feedme.UUCP || {trwrb,hplabs}!felix!dhw68k!feedme!doug Feedme Microsystems:Inventors of the Snarf->Grok->Munge Development Cycle