c++ - De-duplication of NSString & unichar constants -
i have 2 simple constants:
nsstring
andunichar
,
defined follows:
static nsstring * const string = @"\u2022"; static unichar const character = 0x2022;
i'd want have number 0x2022 defined in 1 place.
i tried lot of combinations (#
, ##
, cfstr
macro) no success.
can done?
(using ideas how concatenate twice c preprocessor , expand macro in "arg ## _ ## macro"?):
#define stringify(_x_) #_x_ #define unichar_from_hexcode1(_c_) 0x ## _c_ #define unichar_from_hexcode(_c_) unichar_from_hexcode1(_c_) #define nsstring_from_hexcode1(_c_) @"" stringify(\u ## _c_) #define nsstring_from_hexcode(_c_) nsstring_from_hexcode1(_c_) #define mycharcode 2022 static unichar const character = unichar_from_hexcode(mycharcode); static nsstring * const string = nsstring_from_hexcode(mycharcode);
preprocessed output:
static unichar const character = 0x2022; static nsstring * const string = @"" "\u2022";
(note @"" "\u2022"
equivalent @"\u2022"
.)
Comments
Post a Comment