Sandro Meier
Sandro Meier

Reputation: 3051

Preprocessor error in NSLog

In BlaBlaBla_prefix.pch I define the following:

#import "SMDeviceManager.h"
#define DeviceSpecificResourceName(name) [SMDeviceManager deviceSpecificResourceName:(name)];

But if I know use this function in my code inside a NSog()-call, I get the following error during compilation:

Expected ")" before ";" token.

But if I save the output in a variable ,instead of directly calling the function in NSLog, it works.

NSString *test = DeviceSpecificResourceName(@"eintest.png");
NSLog(@"%@", test);

This logs the expected value. B But in the other way it fails at compiling. What am I doing wrong? Can you please help me?

Upvotes: 0

Views: 147

Answers (1)

kennytm
kennytm

Reputation: 523754

#define DeviceSpecificResourceName(name) [SMDeviceManager deviceSpecificResourceName:(name)];
//                                                                                          ^ remove

Remove the final semicolon.


If you keep the ;, the statement NSLog(@"%@", DeviceSpecificResourceName(@"eintest.png")) will be replaced as

NSLog(@"%@", [SMDeviceManager deviceSpecificResourceName:(@"eintest.png")];);
//                                                                        ^

which of course is a syntax error.

Upvotes: 5

Related Questions