[Pixman] [PATCH 4/4] Various remaining fixes needed for successful compilation with C++

Behdad Esfahbod behdad at behdad.org
Mon Dec 17 09:59:55 PST 2012


On 12-12-16 05:52 PM, Siarhei Siamashka wrote:
> -typedef enum
> -{
> +typedef int cpu_features_t;
> +
> +enum {
>      X86_MMX			= (1 << 0),
>      X86_MMX_EXTENSIONS		= (1 << 1),
>      X86_SSE			= (1 << 2) | X86_MMX_EXTENSIONS,
>      X86_SSE2			= (1 << 3),
>      X86_CMOV			= (1 << 4)
> -} cpu_features_t;
> +};
> 
> Using enum for bit flags is a bit cumbersome in C++:
>     http://stackoverflow.com/questions/199606/how-should-c-bitflag-enumerations-be-translated-into-c

I actually like the operator| approach and always thought it provides exactly
the kind of typesafety that you would hope C++ provides.  A little macro like
this would do:

#ifdef __cplusplus__
#define PIXMAN_FLAG_ENUM(X) \
  static inline X operator| (X a, X b) { \
    return (X) ((unsigned int) a | (unsigned int) b); \
  }
#else
#define PIXMAN_FLAG_ENUM(X)
#endif

-- 
behdad
http://behdad.org/


More information about the Pixman mailing list