Path: utzoo!utgpu!water!watmath!clyde!rutgers!gatech!bloom-beacon!tut.cis.ohio-state.edu!uwmcsd1!ig!agate!ucbvax!hoptoad!gnu From: gnu@hoptoad.uucp (John Gilmore) Newsgroups: comp.lang.c Subject: Macro parameters getting substituted into strings Message-ID: <4253@hoptoad.uucp> Date: 27 Mar 88 13:26:00 GMT References: <11879@brl-adm.ARPA> <4099@hoptoad.uucp> <7309@brl-smoke.ARPA> <983@mcgill-vision.UUCP> Organization: Grasshopper Group in San Francisco Lines: 36 I am not saying that I like the idea of macro parameter names being replaced even inside strings. My complaint is that an ANSI C compiler does not have a capability that Unix C compilers have, and which many Unix programs depend upon. This is the capability to turn a single- character argument into a character constant. MOVING TO ANSI C REQUIRES CHANGING ALL THE **USES**, AS WELL AS ALL THE **DEFINITIONS**, OF MACROS THAT NEED THIS CAPABILITY! In the BSD sources, Keith Bostic and I had to change more than 50 files to deal with this. The CPP on my binary A/UX, supposedly a System V, replaces macro parameters inside strings. I would like someone who has System V sources to grep the sources for the CTRL macro -- I bet you will find it there, using this technique. If it's there, this ANSI change is a "Quiet Change" to the compilers of both major Unix variants (effectively, to ALL Unix implementations) and breaks dozens of the application programs in both variants. Can you say "Codifying existing practice", boyz and goils? My preferred way to fix this would be for ANSI C to allow the * (indirection) and [] (subscripting) operators on string literals in constant expressions. Then the new ANSI "#" operator can be used to create a character string, and * or [] can pull a character out of it, all in a constant expression, e.g.: #define CTRL(x) (# x [0]&0x1F) ... case CTRL(q): turns to: case ("q"[0]&0x1F): I noticed that integer constant expressions are permitted to contain subscripting in the new ANSI draft (Jan 88), but they aren't allowed to contain string literals! Inserting "string literals, " in lines 25 and 35 on page 56, and adding "except the values of string literals" at the end of line 1 of page 57, would fix this. -- {pyramid,ptsfa,amdahl,sun,ihnp4}!hoptoad!gnu gnu@toad.com "Watch me change my world..." -- Liquid Theatre