Re: Headers common to .cpp and .rc files

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"Alex Blekhman" <tkfx.REMOVE@xxxxxxxxx> wrote in message news:uw2Wf9spIHA.3408@xxxxxxxxxxxxxxxxxxxxxxx

You can conduct simplest experiment with following text file:

-------
#define _STR(x) #x
#define STR(x) _STR(x)
#define BUILDSTR STR( BUILDNUMBER )
#define BUILDNUMBER 31

> Open it with any text editor and do search-and-replace while
counting how many times you perform the operation. After each search-and-replace remove the #define that was used (it will be corrupted by the editor anyway). Any time you get #some_token replace it with "some_token" regardles of what `some_token' name may mean.

You'll see the exact flow of the preprocessor.

Ok. I can do that in my head :-) Sorry if I'm being thick here, but I still can't see it.

Sequence 1:

#define _STR(x) #x
#define STR(x) _STR(x)
#define BUILDSTR STR( BUILDNUMBER )
#define BUILDNUMBER 31
.... = BUILDSTR;

Pass 1 gives

#define STR(x) #x
#define BUILDSTR STR( BUILDNUMBER )
#define BUILDNUMBER 31
.... = BUILDSTR;

Pass 2 gives

#define BUILDSTR #BUILDNUMBER
#define BUILDNUMBER 31
.... = BUILDSTR;

Pass 3 gives

#define BUILDNUMBER 31
....= #BUILDNUMBER;

Now two possibilities:

A). Assuming BUILDNUMBER is replaced next, then

....= #31;

and so

....="31";

B) However, if after pass 3, the #-operator were expanded then I get

#define BUILDNUMBER 31
....= "BUILDNUMBER";

and the #define will not replace the contents of the quotes.

But this works correctly and so possibility 2 is not happening.

One could therefore argue that it is just done in order, Except

Sequence 2:

#define STR(x) #x
#define BUILDSTR STR( BUILDNUMBER )
#define BUILDNUMBER 31
.... = BUILDSTR;

you get the same results. But sequence 1 works and sequence 2 doesn't. There must be something going on other than just a sequence of independent passes.

Dave

--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm






.



Relevant Pages