ANSI Preprocessor Was: how widespread is this cpp bug?

Guy Harris guy at auspex.UUCP
Sun Dec 11 11:46:06 AEST 1988


 >#define MAC_RO1(string1, string2) "strings1string2"
 >
 >If you feed MAC_RO1 like so
 >
 >	MAC_RO1(dir, file)
 >
 >you get
 >
 >	"dirfile"
 >
 >Can you accomplish anything similar with ANSI C?

	#define	MAC_RO1(string1, string2) #string1 #string2

should do it, since:

	1) "#" preceding an occurrence of a formal argument in the body
	   of a macro turns it into a string

	2) adjacent string literals are concatenated

hence

	MAC_RO1(dir, file)

gets expanded to

	"dir" "file"

which gets turned into

	"dirfile"

>I guess what I'm asking for is a preprocessor tutorial in respect to
>ANSI-C.

A topic that's probably too big for a posting on comp.lang.c, although
somebody may post some further tutorial information.  You might check
out Kernighan & Ritchie, second edition, which is, to quote the blurb in
the upper right hand corner of the cover, "Based on Draft-Proposed ANSI
C" (BTW, "Draft-Proposed ANSI C" is often abbreviated as dpANS,
especially in this newsgroup). 



More information about the Comp.lang.c mailing list