Re: Preprocessor macro concatenation...
Re: Preprocessor macro concatenation...
- Subject: Re: Preprocessor macro concatenation...
- From: Rush Manbert <email@hidden>
- Date: Thu, 07 Sep 2006 13:51:43 -0700
Ralf Hasemann wrote:
Hi all!
this is not a real Cocoa question - I hope that don't mind.
I am "fighting" adainst the C preprocessor at the moment.
What I like to do is create a #define that does the following:
Inserting a variable with the current source code line number in its name.
Example:
NSString* strNr_25 = [NSString string];
Where 25 is the number of the line in the code file.
The standard predefined macro __LINE__ inserts the current line number.
So far - so good.
but when I try the following:
#define LineString NSString* strNr___LINE__ = [NSString string];
the __LINE__ macro is not replaced because it is joint to "strNr_" and
therefore
not recognized by the preprocessor.
The question is now: Is the a way (a trick / hack) to concatenate the
__LINE__
macro with a string within a define??
Thank you for any help!
Hi Ralf,
Try this:
#define cat(a, b) a ## b
#define xcat(x,y) cat(x,y)
#define LineString NSString * xcat(strNr_,__LINE__) = [NSString string];
I did it with a C++ command line tool, so my LineString looked like this:
#define LineString std::string * xcat(strNr_,__LINE__);
but the build told me about an unused variable with the right name when
I used it, so the macro did what I expected.
Good luck,
Rush
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden