Wireshark mailing list archives

Re: #ifdef mess


From: Dario Lombardo <dario.lombardo.ml () gmail com>
Date: Tue, 29 Mar 2016 11:18:27 +0200

On Tue, Mar 29, 2016 at 3:48 AM, Guy Harris <guy () alum mit edu> 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
}
___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev () wireshark org>
Archives:    https://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request () wireshark org?subject=unsubscribe

Current thread: