Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tcs!nujoizey!gwu From: gwu@nujoizey.tcs.com (George Wu) Newsgroups: comp.lang.c++ Subject: Re: How SHOULD these macros work? Keywords: C preprocessor macros Message-ID: <1771@tcs.tcs.com> Date: 19 Feb 91 03:08:20 GMT References: <9102151600.AA03343@ucbvax.Berkeley.EDU> Sender: root@tcs.com Reply-To: gwu@nujoizey.tcs.com (George Wu) Organization: Teknekron Communications Systems Lines: 39 In article <9102151600.AA03343@ucbvax.Berkeley.EDU>, schweitz@lexvmc.iinus1.ibm.com ("Eric Schweitz") writes: |> |> I have a question concerning the preprocessor. Namely, what behavior |> SHOULD be expected from the following: |> |> #define one val1,val2 |> #define two(arg1,arg2) arg1+arg2 |> .... |> two (one) // ? |> |> Should this evaluate to: |> |> a) val1+val2 |> -or- |> b) val1,val2+ My (Sun 4.1) cpp evaluates this as an error, and I think it's correct, ie. your sample code isn't legal (whatever legal is for the cpp). When expanding macros, the cpp doesn't expand additional macros until the current substitution is complete. In other words, the cpp sees "two" and tries to grab the two arguments within the parenthesis. It finds only one there because the cpp doesn't try to expand "one" until "two" is done. |> Also, is this behavior different of the same for C and C++? For the most part, there are no C or C++ specific definitions of cpp behavior. The only *behavior* difference I know of is having the cpp strip out C++ // comments the same way it removes C comments, and I consider this implementation dependant. There's also the addition of predefined macros, such as __cplusplus and ANSI, but that's just use of existing cpp behavior. George ---- George J Wu, Software Engineer | gwu@tcs.com or uunet!tcs!gwu Teknekron Communications Systems, Inc.| (415) 649-3752 2121 Allston Way, Berkeley, CA, 94704 | Quit reading news. Get back to work.