[ovs-dev] [PATCH 1/5] lib/util.c: add ovs_windows_only() cpp macro

Ben Pfaff blp at nicira.com
Wed Oct 22 15:58:00 UTC 2014


On Tue, Oct 21, 2014 at 04:10:35PM -0700, Nithin Raju wrote:
> It is convenient to have a macro which we can use to wrap Windows
> specific code without using the #ifdef _WIN32/#endif combo each time.
> 
> Signed-off-by: Nithin Raju <nithin at vmware.com>
> ---
>  lib/util.h |    8 ++++++++
>  1 files changed, 8 insertions(+), 0 deletions(-)
> 
> diff --git a/lib/util.h b/lib/util.h
> index f171dbf..32f50e5 100644
> --- a/lib/util.h
> +++ b/lib/util.h
> @@ -76,6 +76,14 @@
>      }
>  NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
>  
> +/* A convenient macro to wrap Windows specific code without having to use
> + * _WIN32 CPP. */
> +#ifdef _WIN32
> +#define ovs_windows_only(CONDITION) CONDITION
> +#else
> +#define ovs_windows_only(CONDITION)
> +#endif

I'm not sure I'm happy about this.

For the only uses of this macro introduced in this patch series, which
are assertions on variables that are always present, the code does not
have to be Windows-only after the preprocessor.  One could simply write:

    #ifdef _WIN32
    enum { WINDOWS = 1 };
    #else
    enum { WINDOWS = 0 };
    #endif

and then add "WINDOWS &&" to the assertions.



More information about the dev mailing list