[lttng-dev] [PATCH] rculfhash: use do {} while (0) for dbg_printf()

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Mon May 7 11:09:00 EDT 2012


* Lai Jiangshan (laijs at cn.fujitsu.com) wrote:
> found by clang(make CC=clang).
> 
> avoid empty statement.
> -------------------------
> if (condition)
> 	dbg_printf()  /* forget ";", but compiler say nothing if dbg_printf() is empty */
> statement;

merged, thanks!

Mathieu

> -------------------------
> 
> also add printf format check.
> (we can use gcc extention "__printf(1, 2)" to declare a dummy inline function
> to do the check, but I use "printf()" directly here)
> 
> Signed-off-by: Lai Jiangshan <laijs at cn.fujitsu.com>
> ---
> diff --git a/rculfhash-internal.h b/rculfhash-internal.h
> index 284125a..d7cec95 100644
> --- a/rculfhash-internal.h
> +++ b/rculfhash-internal.h
> @@ -25,11 +25,17 @@
>   */
>  
>  #include <urcu/rculfhash.h>
> +#include <stdio.h>
>  
>  #ifdef DEBUG
>  #define dbg_printf(fmt, args...)     printf("[debug rculfhash] " fmt, ## args)
>  #else
> -#define dbg_printf(fmt, args...)
> +#define dbg_printf(fmt, args...)				\
> +do {								\
> +	/* do nothing but check printf format */		\
> +	if (0)							\
> +		printf("[debug rculfhash] " fmt, ## args);	\
> +} while (0)
>  #endif
>  
>  #if (CAA_BITS_PER_LONG == 32)
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com



More information about the lttng-dev mailing list