
On Mon, Feb 21, 2011 at 9:19 AM, Edward Diener <eldiener@tropicsoft.com> wrote:
On 2/21/2011 4:05 AM, Paul Mensonides wrote:
On Sun, 20 Feb 2011 20:25:43 -0500, Edward Diener wrote:
I think Paul Mensonides may be right and there is no foolproof way to check for a completely empty parameter list even using variadic macros. Further ideas ?
Trust me, I am right. About the best you can do is prohibit input that terminates in a function-like macro name. You can generally detect emptiness *except* for that case.
However, DATA_SIZE() => 0 is ill-conceived. An empty argument is still an argument to the preprocessor. A better correlation is:
DATA_SIZE(,,) => 3 DATA_SIZE(,) => 2 DATA_SIZE() => 1
Thanks ! I will just have to further document that the data size returned can never be 0, even when the variadic macro is invoked with an empty argument.
IMO, that makes sense -- so documentation is a good option. However, I still don't understand why MSVC accepts this DATA_SIZE() invocation: #define DATA_SIZE(...) DATA_SIZE(1) DATA_SIZE() // No error -- why?? #define SIZE(x) SIZE(1) SIZE() // Error -- as it should! E:\sandbox\boost-sandbox\local\libs\local\example>cl /EHs /I"c:\Program Files\bo ost\boost_1_45_0" /I..\..\.. 01.cpp /EP Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. 01.cpp 01.cpp(8) : warning C4003: not enough actual parameters for macro 'SIZE' I would think that DATA_SIZE() should error (like SIZE() correctly does) because it is invoked with an empty macro parameter... Why does the variadic DATA_SIZE() not error on MSVC given that MSVC does not support empty macro parameters? -- Lorenzo