开发者

getting errors using macros in Objective-C

I am new to Objective-C. I was trying out a sample program using macros and getting errors.

#import <Foundation/Foundation.h>

#define HELLO_WORLD @"Hell开发者_运维技巧o World"

#define a(x,y) ((x)+(y))

#define PRINTMAC(x,y)\
NSLog(@"%d",a((x),(y));\

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    // insert code here...
    //NSLog(@"%d",add(10,20));
    PRINTMAC(13,72);  //error:
    [pool drain];
    return 0;
} //error:

Error: expected ';' before '}' token


You appear to be missing a ) on the NSLog line (line 8).

Additionally, I'm not sure you need the final \ on that line, as the macro is not being carried on to a third line.

Finally, I don't think you need the ; on that line either as it, combined with the semi-colon when you invoke the macro on line 15 results in an empty statement (shouldn't be harmful, though).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜