Affan said:
Can any body give me an idea what the heck is happening over here
#define UARTOutput(__x,__y,__args...) do { \
static char __s[] PROGMEM = __y; \
if (debug_out) \
printf_P(__s, ## __args); \
} while (0)
Thankyou.
It looks like it's a printf like macro. UARTOutput( unused, "%s\n", "str");
It however, isn't C++ (or for that matter standard C). C++ doesn't have the
variable arg construct, and this doesn't look like it's using the C facility
for doing such correctly either.
The do { ... } while(0) construct is a macro writers hack to make the multiple
statements look like a single function without causing grief to things that can
only eat a single statement. For example, a simpler example:
#define F(x) ++x; printf("%d\n", x)
would perform wierdly in this sort of instance:
if(condition) F(x) ;
If the condition were false, the ++x would not be executed, but the printf would be.
If you wrap the do...while around it it then behaves more as expected.