Simplified NSLog Macro

using iphone sdk 4.0 I want to remove the function name from this macro, but I'm struggling

#define LOG(fmt, ...) NSLog((@"%s " fmt), __PRETTY_FUNCTION__,##__VA_ARGS__) 

I tried

 #define LOG(fmt, ...) NSLog((@"%s " fmt), ##__VA_ARGS__) 

but it crashes!

I want to be able to register as follows

 LOG("text to log"); LOG("text to log with param %d", param); etc 
+4
source share
3 answers

Why not just like that?

 #define LOG(fmt, ...) NSLog(fmt, ##__VA_ARGS__) 
+6
source

I think you want this

 #define Log(fmt, ...) NSLog(fmt, ##__VA_ARGS__); 
+1
source

You should wrap your log macro in do {} while (0); to avoid the possibility of errors with if statements

cm.

do {...} while (0) - what is it useful for?

0
source

Source: https://habr.com/ru/post/1315515/


All Articles