Re: capture #define value?
Re: capture #define value?
- Subject: Re: capture #define value?
- From: Greg Guerin <email@hidden>
- Date: Sat, 30 Jan 2010 12:13:24 -0700
Matt Neuburg wrote:
I'm passing a name-and-value into my code via the build process,
thru the
preprocessor macros build setting. All well and good; using #ifdef and
logging I can tell that the #define of the *name* is working. My
question
is: can my *code* capture the *value* as an NSString? (And if so,
how?) Thx
Is the value of the macro a string literal, e.g. "some text here" or
@"some text here"?
If so, then just use the macro itself for @"some text here", or one
of the NSString init methods for "some text here".
If the value of the macro isn't a string literal, but is some kind of
numeric value (as distinct from a numeric expression), then you can
capture the value (but not the expression) something like:
NSString* ref = [NSString stringWithFormat:@"%d", MACRO_HERE];
E.g. if MACRO_HERE were defined as 450, then ref would be an NSString
containing "450". But if MACRO_HERE were define as 9*50, ref would
still be "450", not "9*50".
If the macro value is a float or double, you'd have to change the
format specifier.
Otherwise I don't think there's any way to stringize the unexpanded
value of a macro. Stringizing other things, yes: use C standard
stringizing.
PS Or feel free to tell me that there's a better way for the build
process
to send messages to my code.
What kind of messages do you need to send to your code? Strings,
numbers, expressions, statements, blocks?
-- GG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden