<p>As far as I know, in gcc you can write something like:</p>

<pre><code>#define DBGPRINT(fmt...) printf(fmt);
</code></pre>

<p>Is there a way to do that in VC++?</p>

[{'answer_id': 65067, 'author': 'kfh', 'author_id': 6597, 'author_profile': 'https://Stackoverflow.com/users/6597', 'pm_score': -1, 'selected': False, 'text': '<p>Almost. It\'s uglier than that though (and you probably don\'t want a trailing semi-colon in the macro itself:</p>\n\n<pre><code>#define DBGPRINT(DBGPRINT_ARGS) printf DBGPRINT_ARGS // note: do not use \'(\' &amp; \')\'\n</code></pre>\n\n<p>To use it:</p>\n\n<pre><code>DBGPRINT(("%s\\n", "Hello World"));\n</code></pre>\n\n<p>(was missing a pair of parens).</p>\n\n<p>Not sure why all the negatives, the original question didn\'t state a version of VC++, and variadic macros aren\'t supported by all compilers.</p>\n'}, {'answer_id': 65077, 'author': 'Mark', 'author_id': 4405, 'author_profile': 'https://Stackoverflow.com/users/4405', 'pm_score': 2, 'selected': False, 'text': "<p>Yes, you can do this in Visual Studio C++ in versions 2005 and beyond (not sure about VS 2003).  Take a look at <strong>VA_ARGS</strong>.  You can basically do something like this:</p>\n\n<pre><code>#define DBGPRINTF(fmt, ...)  printf(fmt, __VA_ARGS__)\n</code></pre>\n\n<p>and the variable arguments to the macro will get passed to the function provided as '...' args, where you can then us va_args to parse them out.</p>\n\n<p>There can be weird behavior with <strong>VA_ARGS</strong> and the use of macros.  Because <strong>VA_ARGS</strong> is variable, that means that there can be 0 arguments.  That might leave you with trailing commas where you didn't intend.  </p>\n"}, {'answer_id': 65083, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>What you\'re looking for are called [variadic macros](<a href="http://msdn.microsoft.com/en-us/library/ms177415(VS.80).aspx)" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms177415(VS.80).aspx)</a>.</p>\n\n<p>Summary of the link: yes, from VC++ 2005 on up.</p>\n'}, {'answer_id': 65087, 'author': 'David Dolson', 'author_id': 8566, 'author_profile': 'https://Stackoverflow.com/users/8566', 'pm_score': 0, 'selected': False, 'text': '<p>The following should work. (See link to <a href="http://msdn.microsoft.com/en-us/library/ms177415(VS.80).aspx" rel="nofollow noreferrer">Variadic macros</a>)</p>\n\n<p>(Example below shows a fixed and variable arguments.)</p>\n\n<pre><code>#  define DBGPRINTF(fmt,...) \\\n    do { \\\n        printf(fmt, __VA_ARGS__); \\\n    } while(0)\n</code></pre>\n'}, {'answer_id': 65103, 'author': 'Gareth Simpson', 'author_id': 147, 'author_profile': 'https://Stackoverflow.com/users/147', 'pm_score': 6, 'selected': True, 'text': '<p>Yes but only since VC++ 2005.  The syntax for your example would be:</p>\n\n<pre><code>#define DBGPRINT(fmt, ...) printf(fmt, __VA_ARGS__)\n</code></pre>\n\n<p>A full reference is <a href="http://msdn.microsoft.com/en-us/library/ms177415(VS.80).aspx" rel="noreferrer">here</a>.</p>\n'}, {'answer_id': 65158, 'author': 'James', 'author_id': 168235, 'author_profile': 'https://Stackoverflow.com/users/168235', 'pm_score': 0, 'selected': False, 'text': '<p>Search for "<strong>VA_ARGS</strong>" and va_list in MSDN!</p>\n'}, {'answer_id': 65388, 'author': 'yrp', 'author_id': 7228, 'author_profile': 'https://Stackoverflow.com/users/7228', 'pm_score': 2, 'selected': False, 'text': '<p>If you do not want to use non-standard extensions, you\'ve to provide extra brackets:    </p>\n\n<pre><code>#define DBGPRINT(args) printf(args);\nDBGPRINT(("%s\\n", "Hello World"));\n</code></pre>\n'}, {'answer_id': 69151, 'author': 'bk1e', 'author_id': 8090, 'author_profile': 'https://Stackoverflow.com/users/8090', 'pm_score': 1, 'selected': False, 'text': "<p>If you don't actually need any of the features of macros (<code>__FILE__</code>, <code>__LINE__</code>, token-pasting, etc.) you may want to consider writing a variadic function using <code>stdargs.h</code>. Instead of calling <code>printf()</code>, a variadic function can call <code>vprintf()</code> in order to pass along variable argument lists.</p>\n"}, {'answer_id': 16365801, 'author': 'amarcruz', 'author_id': 2347894, 'author_profile': 'https://Stackoverflow.com/users/2347894', 'pm_score': 1, 'selected': False, 'text': '<p>For MSVC 7.1 (.NET 2003), this works:</p>\n\n<pre><code>#if defined(DETAILED_DEBUG)\n#define DBGPRINT fprintf\n#else\n__forceinline void __DBGPRINT(...){}\n#define DBGPRINT __DBGPRINT\n#endif\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/65037', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9102/']