"Expression Expected" error with macro functions
Hi!
AppCode seems to have a problem with our logging macro. Code looks like this:
LOG_INFO(@"Message.");
And the error message for that line is "Expression Expected".
Macro is defined as:
#define LOG_INFO(s,...) LOG_LOG(@"INFO", LOG_LEVEL_INFO, s, ##__VA_ARGS__)
LOG_LOG macro is defined as:
#define LOG_LOG(lname, llevel, s, ...) \
do { \
// do the logging stuff using ##__VA_ARGS__ etc...
} while(0)
The code compiles fine, and neither gcc nor clang have any problems with it. I know C macros can be hairy, but I'd hope this could be fixed in AppCode, because we use logging everywhere in our code and it isn't nice to see AppCode think all the files have errors.
Thanks again for making AppCode!
Please sign in to leave a comment.
Hi!
Unfortunately (or fortunately it is?) I wasn't able to reproduce the problem. Can I have a complete sample code?
Hi!
Sorry about the bad code. I hope this is complete enough for you to replicate the problem. At least for me it showed the warning when pasted to any Objective-C file.
Thanks for looking into this! And good luck fixing :)
@interface Logger : NSObject
+(void)logFormat:(NSString*)format, ...;
@end
extern int gLogLevel;
#define LOG_LOG(level, s, ...) \
do { \
if(level <= gLogLevel)\
{\
[Logger logFormat:s, ##__VA_ARGS__]; \
}\
} while(0)
#define LOG_INFO(s,...) LOG_LOG(1, s, ##__VA_ARGS__)
@interface MyViewController : UIViewController
{}
@end
@implementation MyViewController
-(void) viewDidUnload
{
[super viewDidUnload];
LOG_INFO(@"Message.");
@end
Got it!
-- gone fixing
Fixed. http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html helped alot
Superb! Thanks! Really looking forward to the next build.
I'm experiencing the same problem with 106.624 - should your fix be part of this new build?
regards,
Christian K. Ibsen