iphone - Comma inside a statement inside a macro being misinterpreted as a macro argument separator -


i created xcode project , wrote following code:

#define foo(x) x - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {     int n = 666;     nsstring* string = foo([nsstring stringwithformat: @"%d", n]);     nslog (@"string %@", string);     [self.window makekeyandvisible];         return yes; } 

when try run this, bunch of errors, because preprocessor decides that comma after stringwithformat: supposed separating 2 macro arguments, therefore have used foo 2 arguments instead of correct one.

so when want comma inside statement inside macro, can do?

this c++ question suggests way put round parens () around comma, apparently leads preprocessor realize comma not macro argument separator. off top of head, i'm not thinking of way in objective c.

adding additional parentheses around call works:

nsstring* string = foo(([nsstring stringwithformat:@"%d",n])); 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -