Make bitfield.h C++-friendly
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 20 Aug 2019 01:54:07 +0000 (21:54 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 26 Aug 2019 17:55:20 +0000 (13:55 -0400)
This patch changes bitfield.h to be usable in C++11.

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

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Ib0fa31ee08d0f691841f96676556d2aa9fcd2426
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1965
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/compat/bitfield.h

index e2f2c128ed79ad5048099ef042928b2743b6c5c4..72c857c4fbce0348266e6304b19b08f5a7e3dc3b 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`.
@@ -377,7 +381,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.024981 seconds and 4 git commands to generate.