Can pre-ANSI C Preprocessor handle symbolic constants in strings?

Brumley David M dlbres14 at pc.usl.edu
Fri May 31 20:03:15 AEST 1991


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)?

P.S. I've searched the FAQ list, and the Second (ANSI) edition of K&R
to no avail.  


	
--
David M. Brumley
<dmb8516 at usl.edu>



More information about the Comp.lang.c mailing list