Path: utzoo!attcan!uunet!sdrc!scjones From: scjones@sdrc.UUCP (Larry Jones) Newsgroups: comp.lang.c Subject: Re: Preprocessor question Message-ID: <509@sdrc.UUCP> Date: 19 Jan 89 22:41:44 GMT References: <531@ole.UUCP> Distribution: na Organization: Structural Dynamics Research Corp., Cincinnati Lines: 27 In article <531@ole.UUCP>, ray@ole.UUCP (Ray Berry) writes: > > #define VAL 3 > #define STR(x) #x > - - - - - - - - > 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? Microsoft is correct (Horray!!!); the stringize operator stringizes the actual argument. To stringize the replacement you just need one more level of indirection: #define VAL 3 #define STR(x) #x #define REPSTR(x) STR(x) Now when you write REPSTR(VAL) it gets replaced with STR(3) which is rescanned and replaced with "3". ---- Larry Jones UUCP: uunet!sdrc!scjones SDRC scjones@sdrc.UU.NET 2000 Eastman Dr. BIX: ltl Milford, OH 45150 AT&T: (513) 576-2070 "When all else fails, read the directions."