Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] C99 variadic arguments in macros
Home

[Freeciv-Dev] C99 variadic arguments in macros

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] C99 variadic arguments in macros
From: Jason Short <jshort@xxxxxxxxxxxxxx>
Date: Mon, 22 Sep 2003 16:13:38 -0400
Reply-to: jdorje@xxxxxxxxxxxxxxxxxxxxx

Say we have some variadic arguments in a macro:

#define notify(pplayer, text, ...)                                     \
  if (diplomacy_verbose) {                                             \
    notify_player_ex(pplayer, -1, -1, E_DIPLOMACY, text, __VA_ARGS__); \
  }

Oddly enough the __VA_ARGS__ is not the same as a va_list "variable", but is actually the direct substition of '...'. So the above is correct while

static void notify(struct player *pplayer, const char *text, ...)
{
  if (diplomacy_verbose) {
    va_list ap;
    struct conn_list *dest = (struct conn_list*)&pplayer->connections;

    va_start(ap, text);
    vnotify_conn_ex(dest, -1, -1, E_DIPLOMACY, text, ap);
    va_end(ap);
  }
}

is the function form.

This can easily lead to confusion. But it seems the macro form would be preferable for several reasons; the only drawback is that it requires C99.

jason



[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] C99 variadic arguments in macros, Jason Short <=