Advertisement

macros with ...

Started by June 02, 2001 03:38 AM
1 comment, last by mattd 23 years, 8 months ago
ok, lets say i have this function here: void OutDebugString(LPCSTR szFile, int nLine, LPCSTR szFormat, ...); how can i create a macro (or #define thingy, whaddever) that lets me do something like this: _DEBUGOUT("MMM... %s, %d slices please!", "cheese", 1234); _DEBUGOUT("Lalala, lalala!"); this dosen't work not surprisingly: #define _DEBUGOUT(a, ...) OutDebugString(__FILE__, __LINE__, a, ...); so how can i have a macro that takes a unknown amount of args? (the ... thing, i forgot what it's called ) or can someone else suggest another method? thanks, mattd ----------------------------------------------------- Joe's appliance repair company! If God didn't assemble it, we can repair it! Edited by - mattd on June 2, 2001 4:40:31 AM
I tried to do that too, and reached the conclusion that it cannot be done. I used something like this instead :

#define SAY(x) {OutDbgStr (x);}
#define SAY1(x,y) {OutDbgStr (x,y);}
#define SAY2(x,y,z) {OutDbgStr (x,y,z);}
Advertisement
Macros can''t use the ellipsis as a parameters for parameters lists. It''s among the things that they were not meant to do. Just create an inline function that takes one, then look up va_start, va_end, and vprintf.

Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/ (If my website isn''t down, it''s a miracle!)

This topic is closed to new replies.

Advertisement