VS2005 - ellipsis in a macro
-
VS6 and VS2003 do not support varargs in a C macro. The link http://sourceforge.net/mailarchive/forum.php?forum_id=40270&max_rows=25&style=nested&viewmonth=200503[^] hints that this is possible in VS2005. I dont have VS2005 installed, can someone who has VS2005 quickly check if the following compiles?
#define myprint(fmt, args_...) _snprintf(str, fmt, ##args_) char str[64]; myprintf("hello %s", "world");
thanks! -
VS6 and VS2003 do not support varargs in a C macro. The link http://sourceforge.net/mailarchive/forum.php?forum_id=40270&max_rows=25&style=nested&viewmonth=200503[^] hints that this is possible in VS2005. I dont have VS2005 installed, can someone who has VS2005 quickly check if the following compiles?
#define myprint(fmt, args_...) _snprintf(str, fmt, ##args_) char str[64]; myprintf("hello %s", "world");
thanks!VC8 does support it, you've got the syntax wrong though. It should be
#define foo(fmt,...) _snprintf(str,fmt,__VA_ARGS__)
More info[^] --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
VC8 does support it, you've got the syntax wrong though. It should be
#define foo(fmt,...) _snprintf(str,fmt,__VA_ARGS__)
More info[^] --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
Cool, that is what I was looking for. Thanks. Now one more thing - is there any preprocessor variable that indicates what compiler is compiling the code? I want to write this macro seperately once for VC8 and once for VC6/VC7 so that the code can still be compiled with the older compiler, just in case someone wants to use the older compilers. thanks!
-
Cool, that is what I was looking for. Thanks. Now one more thing - is there any preprocessor variable that indicates what compiler is compiling the code? I want to write this macro seperately once for VC8 and once for VC6/VC7 so that the code can still be compiled with the older compiler, just in case someone wants to use the older compilers. thanks!
Chintoo723 wrote:
is there any preprocessor variable that indicates what compiler is compiling the code?
Yep, look up
_MSC_VER
in the help --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ