(Forwarded from offline email)

> Steven Stallion wrote:
>> Sebastien Roy wrote:
>>> On Sat, 2008-08-09 at 11:17 -0500, Steven Stallion wrote:
>>>> Does Studio 11/uts support any macros which allow varargs to be
passed to a macro (__VA_ARGS__ comes to mind)?
>>> Yes; look for existing uses of __VA_ARGS__ in the ON source.
>>> -Seb
>>
>> Consider the following:
>>
>>     static void ne_cmn_err(dev_info_t *, int, const char *, ...);
>>
>>     #define ne_error(dip, format, ...) \
>>         ne_cmn_err((dip), CE_WARN, (format), __VA_ARGS__)
>>
>> If issued without varargs, the preprocessor incorrectly expands the
ne_error macro as:
>>
>>     ne_cmn_err(dip, level, format, ); /* note extraneous comma */
>>
>> Odd... I seem to recall this working just fine on studio 12 - is this a
limitation of 11 or am I missing something?
>
> I believe the same thing exists in GCC and you need to
> do a D(x, args...) plus a ##args in place of __VA_ARGS__
> to get rid  of the comma for this case...

(I'm kicking myself at the moment.)

>From what I gather, variadic macros work a bit differently than their
function counterparts; It seems that the macro must have at least 1 vararg
passed in for the signature to match correctly (although ironically cc -E
shows correct expansion, however the compiler still balks). The simplest
solution was to drop the format argument:

#define ne_error(dip, ...) \
    ne_cmn_err((dip), CE_WARN, __VA_ARGS__)

This ensures that format must always be passed it at a minimum. I suppose
this could be considered macro abuse, but then again, what isn't? ;)

Steve



_______________________________________________
driver-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/driver-discuss

Reply via email to