git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Use __VA_ARGS__ for all of error's arguments

From
Jeff King <peff@peff.net>
Date
Feb 8, 2013, 04:24 UTC
Message-ID
<20130208042428.GA4157@sigill.intra.peff.net>
In-Reply-To
<1360272632-22566-1-git-send-email-kraai@ftbfs.org>
On Thu, Feb 07, 2013 at 01:30:32PM -0800, Matt Kraai wrote:
Show 7 quoted lines
> From: Matt Kraai <matt.kraai@amo.abbott.com>
> 
> QNX 6.3.2 uses GCC 2.95.3 by default, and GCC 2.95.3 doesn't remove the
> comma if the error macro's variable argument is left out.
> 
> Instead of testing for a sufficiently recent version of GCC, make
> __VA_ARGS__ match all of the arguments.

Thanks, this looks better than the original (we do not assume a C99 compiler, so just doing this unconditionally would probably break some other older systems which do not use gcc).

Show 11 quoted lines
>  /*
>   * Let callers be aware of the constant return value; this can help
> - * gcc with -Wuninitialized analysis. We have to restrict this trick to
> - * gcc, though, because of the variadic macro and the magic ## comma pasting
> - * behavior. But since we're only trying to help gcc, anyway, it's OK; other
> - * compilers will fall back to using the function as usual.
> + * gcc with -Wuninitialized analysis.
>   */
>  #if defined(__GNUC__) && ! defined(__clang__)
> -#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
> +#define error(...) (error(__VA_ARGS__), -1)

Should you be dropping most of the comment like this? I would expect it to be more like:

  We have to restrict this trick to gcc, though, because we do not
  assume all compilers support variadic macros. But since...

Other than that, I think it is OK. The compiler will still catch "error()" with no arguments and generate the appropriate diagnostic (in fact, it is better, because the error is now passing too few args to a function, not to the macro).

-Peff
Previous: Matt KraaiNext: Matt Kraai
Message 6 of 9 in “Use __VA_ARGS__ for all of error's arguments”
  1. Use __VA_ARGS__ for all of error's argumentsMatt Kraai, Feb 7, 2013
  2. Junio C HamanoFeb 7, 2013
  3. John KeepingFeb 7, 2013
  4. Matt KraaiFeb 7, 2013
  5. Use __VA_ARGS__ for all of error's argumentsMatt Kraai, Feb 7, 2013
  6. Jeff KingFeb 8, 2013
  7. Matt KraaiFeb 8, 2013
  8. Use __VA_ARGS__ for all of error's argumentsMatt Kraai, Feb 8, 2013
  9. Jeff KingFeb 8, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.