Make bitfield.h C++-friendly
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 20 Aug 2019 01:51:52 +0000 (21:51 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 20 Aug 2019 02:03:23 +0000 (19:03 -0700)
This patch changes bitfield.h to be usable in C++11.

It will probably never be compiled as C++ in the context of
lttng-modules, but this is just to keep things sync'ed across projects.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lib/bitfield.h

index a9e268b4153031d9eb10ccae39df17c5f310b7ed..7d5eaeaa068ddadb7631d9f88750453bc9aa47a2 100644 (file)
  * Produce a build-time error if the condition `cond` is non-zero.
  * Evaluates as a size_t expression.
  */
+#ifdef __cplusplus
+#define _BT_BUILD_ASSERT(cond) ([]{static_assert((cond), "");}, 0)
+#else
 #define _BT_BUILD_ASSERT(cond)                                 \
        sizeof(struct { int f:(2 * !!(cond) - 1); })
+#endif
 
 /*
  * Cast value `v` to an unsigned integer of the same size as `v`.
@@ -362,7 +366,7 @@ do {                                                                        \
 do {                                                                   \
        __typeof__(*(vptr)) *_vptr = (vptr);                            \
        __typeof__(*_vptr) _v;                                          \
-       type *_ptr = (void *) (ptr);                                    \
+       type *_ptr = (type *) (ptr);                                    \
        unsigned long _start = (start), _length = (length);             \
        type _mask, _cmask;                                             \
        unsigned long _ts = sizeof(type) * CHAR_BIT; /* type size */    \
This page took 0.027225 seconds and 4 git commands to generate.