Re: [PATCH] strbuf: use designated initializers in STRBUF_INIT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jul 15, 2017 at 07:43:09AM +0900, Mike Hommey wrote:

> >  - There were occasional cases where we wished if variable-length
> >    arrays, flexible array members and variadic macros were available
> >    in our codebase during the course of this project.  We would
> >    probably want to add a similar test baloon patch for each of
> >    them to this series that is currently two-patch long.
> 
> FWIW, variadic macros have subtle implementation differences that can
> cause problems.
> For instance, MSVC only supports ##__VA_ARGS__ by way of
> ignoring ## somehow, but has the default behavior of dropping the comma
> when __VA_ARGS__ is empty, which means , __VA_ARGS__ *without* ## has a
> different behavior.
> See also https://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement

When there's any other non-optional argument, you can work around this
by just lumping that argument in with the varargs. So don't do:

  #define FOO(fmt, ...) printf(fmt, __VA_ARGS__)

which fails when the format has no placeholders.  Instead do:

  #define FOO(...) printf(__VA_ARGS__)

That limits your interface for variadic macros, but in practice it
doesn't usually come up (there are also disgusting macro tricks you can
do to cover the true 0-arg case portably, but we haven't had to turn to
them yet).

-Peff



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux