Wireshark-dev: Re: [Wireshark-dev] #ifdef mess
From: Dario Lombardo <dario.lombardo.ml@xxxxxxxxx>
Date: Tue, 29 Mar 2016 11:18:27 +0200
On Tue, Mar 29, 2016 at 3:48 AM, Guy Harris <guy@xxxxxxxxxxxx> wrote:

which is a bit of a greasy hack - appending an empty string to str, just so it's marked as used - but I suspect the extra CPU time spent doing that, on platforms unlucky enough not to have zlib, will be lost in the noise.

I would not go with splitting the prototype with #define. It makes the code hard to read. But calling g_string_append_printf() with a null string makes an unnecessary call. Maybe the compiler is so smart to unroll all the code and use a noop instead of the call, but I'm not an expert.

Other possible hacks (more readable or faster)

hack 1:

#if defined(HAVE_LIBZ) && !defined(_WIN32)
#define ZLIB_PARAM_UNUSED
#else
#define ZLIB_PARAM_UNUSED  _U_
#endif 

get_reordercap_runtime_info(GString *str ZLIB_PARAM_UNUSED)
{
    /* zlib */
#if defined(HAVE_LIBZ) && !defined(_WIN32)
    g_string_append_printf(str, ", with libz %s", zlibVersion());
#endif
}

hack 2:

#define UNUSED(x) (void*)(x)

static void
get_reordercap_runtime_info(GString *str)
{
    /* zlib */
#if defined(HAVE_LIBZ) && !defined(_WIN32)
    g_string_append_printf(str, ", with libz %s", zlibVersion());
#else
   UNUSED(str);
#endif
}