Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!uakari.primate.wisc.edu!sdd.hp.com!wuarchive!bcm!shell!shell!rjohnson From: rjohnson@shell.com (Roy Johnson) Newsgroups: comp.lang.c Subject: Re: Can pre-ANSI C Preprocessor handle symbolic constants in strings? Message-ID: Date: 4 Jun 91 15:13:40 GMT References: Sender: usenet@shell.shell.com (USENET News System) Organization: Shell Development Company, Bellaire Research Center, Houston, TX Lines: 32 In-Reply-To: dlbres14@pc.usl.edu's message of 31 May 1991 10:03:15 GMT In article dlbres14@pc.usl.edu (Brumley David M) writes: > In ANSI C it seems possible to use the Preprocessor to do macro > substitution of constants in strings: > #define FIELDSIZE 42 > #define quote(val) #val > char buffer[FIELDSIZE+1]; > ... > /* read a field of length FIELDSIZE */ > scanf("%" quote(FIELDSIZE) "s", buffer); > ... > So that after the Preprocessor, the 'scanf' call becomes: > scanf("%42s", buffer); > Question: How do I do this with a preprocessor that doesn't > understand the new ANSI '#' operator nor string concatenation? Do I > have to build the string argument dynamically (allocating an extra > buffer in the process)? You might, for this example, want to do scanf("%*s", FIELDSIZE, buffer); which is standard/portable. Otherwise you will have to hack string concatenation until you get an ANSI compiler. -- =============== !You!can't!get!here!from!there!rjohnson =============== Feel free to correct me, but don't preface your correction with "BZZT!" Roy Johnson, Shell Development Company