Path: utzoo!attcan!uunet!lll-winken!ames!pasteur!ucbvax!ulysses!gsf From: gsf@ulysses.homer.nj.att.com (Glenn Fowler[eww]) Newsgroups: comp.lang.c Subject: Re: Preprocessor question Summary: unless subject to # or ## Message-ID: <11125@ulysses.homer.nj.att.com> Date: 20 Jan 89 02:55:05 GMT References: <531@ole.UUCP> <9433@smoke.BRL.MIL> Organization: AT&T Bell Laboratories, Murray Hill Lines: 33 In article <9433@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn ) writes: > In article <531@ole.UUCP> ray@ole.UUCP (Ray Berry) writes: > >#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? > > "Before being substituted, each argument's preprocessing tokens are > completely macro replaced as if they formed the rest of the > translation unit; no other preprocessing tokens are available." > > So VAL is first expanded to 3 then the #3 is performed to produce > "3". unless things changed from the 86 draft, macro arguments subject to the # and ## operators are not expanded before the # and ## operations, so the above eventually produces: puts ( "val is VAL" ) ; to get VAL expanded add one more macro level: #define STR(x) #x #define XSTR(x) STR(x) puts(STR(VAL) " is " XSTR(VAL)); to eventually get: puts ( "VAL is 3" ) ; -- Glenn Fowler (201)-582-2195 AT&T Bell Laboratories, Murray Hill, NJ uucp: {att,decvax,ucbvax}!ulysses!gsf internet: gsf@ulysses.att.com