Skip to main content
gamedev.net
🔒 Locked

Variable argument Macro

Started by Axiverse Nov 26, 2004 at 10:34 AM 6 replies 1.3k views
Original Post
Axiverse
Axiverse
does anyone know how to make a macro that takes multiple arguments? (for use with functions that have "..." or variable arguments )
tHiSiSbOb
tHiSiSbOb
I don't quite understand your question. Is it that you need to create functions with variable arguments and don't know how? If that's the case, look at this OpenGL tutorial on NeHe: click. Take a look at the glPrint function. In it he uses variable arguments. This is how I learned. You will need stdarg.h. If you need further help, consult that msdn pages or post some more. Sorry if this isn't what you needed.
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
Arild Fines
Arild Fines
It's not a part of standard C++, nor is it in C89, but I think C99 may have some support for it(not a lot of compilers supporting C99 out there, though). GCC lets you define variadic macros like this:

#define PRINTF_DEBUG( format, args...) xprintf( putc_debug, format, args )

VC++ does not, to my knowledge, have any support for variadic macros.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Axiverse
Axiverse
err... i just want a to make a macro that uses swprintf and _scwprintf, but you would only have to write it in once...


something like:

PString result = new String ( false, _scwprintf ( formatstring, args ) );swprintf ( *result, formatstring, args  );


where args could be multiple arguments...
Puzzler183
Puzzler183
Variadic macros are also standard in C; the syntax has been given so I don't need to go into that.
mother
mother
This works, but is a bit ugly:

// The define:
#define MYPRINTF(args) printf args

// Usage: Note the double-bracketing.
MYPRINTF(("num=%d\n", num));

Tricky huh?

james

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.