[lttng-modules] Make bitfield.h C++-friendly
diff mbox series

Message ID 20190820015152.22528-1-simon.marchi@efficios.com
State Accepted, archived
Headers show
Series
  • [lttng-modules] Make bitfield.h C++-friendly
Related show

Commit Message

Simon Marchi Aug. 20, 2019, 1:51 a.m. UTC
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 at efficios.com>
---
 lib/bitfield.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Mathieu Desnoyers Aug. 20, 2019, 2:04 a.m. UTC | #1
Merged into master branch, thanks!

Mathieu

----- On Aug 19, 2019, at 6:51 PM, Simon Marchi simon.marchi at efficios.com wrote:

> 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 at efficios.com>
> ---
> lib/bitfield.h | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/bitfield.h b/lib/bitfield.h
> index a9e268b41530..7d5eaeaa068d 100644
> --- a/lib/bitfield.h
> +++ b/lib/bitfield.h
> @@ -55,8 +55,12 @@
>  * 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 */	\
> --
> 2.23.0
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Patch
diff mbox series

diff --git a/lib/bitfield.h b/lib/bitfield.h
index a9e268b41530..7d5eaeaa068d 100644
--- a/lib/bitfield.h
+++ b/lib/bitfield.h
@@ -55,8 +55,12 @@ 
  * 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 */	\