Path: utzoo!attcan!uunet!lll-winken!ncis.llnl.gov!helios.ee.lbl.gov!pasteur!ucbvax!decwrl!hplabs!hpda!hpcuhb!hpcllla!hpcllca!curtw From: curtw@hpcllca.HP.COM (Curt Wohlgemuth) Newsgroups: comp.lang.c Subject: Re: Preprocessor question Message-ID: <7330012@hpcllca.HP.COM> Date: 19 Jan 89 20:53:03 GMT References: <531@ole.UUCP> Organization: HP NSG/ISD California Language Lab Lines: 36 ray@ole.UUCP (Ray Berry) writes: > > Here's an easy question regarding preprocessor string-izing and subsequent > rescanning... > > #define VAL 3 > #define STR(x) #x > . > . > puts("val is " STR(VAL)); > - - - - - - - - > Turbo C produces "3" for STR(VAL); Microsoft produces "VAL" and > leaves it at that. > Which behavior is correct? Further, if Microsoft's is correct, how can > one parenthesize a #define'd value to turn it into a character string? According to ANSI, 'VAL' is substituted into the 'STR' macro, gets quoted, and then is NOT subject to macro replacement as a result. If you want to "parenthesize a #define'd value to turn it into a character string", try this: #define VAL 3 #define STR(x) #x #define XSTR(x) STR(x) main() { puts("val is " XSTR(VAL)); } Now after VAL is substituted into XSTR, it has not yet been quoted, so it is subject to macro replacement. It appears that the Microsoft compiler is ANSI-conforming here, whereas the Turbo C one is not.