[U-Boot] [PATCH 1/4] COMMON: Add __stringify() function

Albert ARIBAUD albert.u.boot at aribaud.net
Sun Sep 23 19:02:00 CEST 2012


Hi Marek,

On Sun, 23 Sep 2012 17:41:22 +0200, Marek Vasut <marex at denx.de> wrote:

> Copied from Linux kernel:
> commit 8f7c2c37319a81ef4c2bfdec67b1ccd5744d97e4
> Date:   Wed Apr 8 16:58:57 2009 +0800
> 
> This function converts static number to string in preprocessor.
> This is useful as it allows higher usage of puts() in favour of printf()

Fix commit message: this fonction is not limited to numbers.
 
> Signed-off-by: Marek Vasut <marex at denx.de>
> Cc: Wolfgang Denk <wd at denx.de>
> ---
>  include/common.h          |    1 +
>  include/linux/stringify.h |   12 ++++++++++++
>  2 files changed, 13 insertions(+), 0 deletions(-)
>  create mode 100644 include/linux/stringify.h
> 
> diff --git a/include/common.h b/include/common.h
> index 55025c0..9937a57 100644
> --- a/include/common.h
> +++ b/include/common.h
> @@ -39,6 +39,7 @@ typedef volatile unsigned char	vu_char;
>  #include <linux/bitops.h>
>  #include <linux/types.h>
>  #include <linux/string.h>
> +#include <linux/stringify.h>
>  #include <asm/ptrace.h>
>  #include <stdarg.h>
>  #if defined(CONFIG_PCI) && (defined(CONFIG_4xx) && !defined(CONFIG_AP1000))
> diff --git a/include/linux/stringify.h b/include/linux/stringify.h
> new file mode 100644
> index 0000000..841cec8
> --- /dev/null
> +++ b/include/linux/stringify.h
> @@ -0,0 +1,12 @@
> +#ifndef __LINUX_STRINGIFY_H
> +#define __LINUX_STRINGIFY_H
> +
> +/* Indirect stringification.  Doing two levels allows the parameter to be a
> + * macro itself.  For example, compile with -DFOO=bar, __stringify(FOO)
> + * converts to "bar".
> + */
> +
> +#define __stringify_1(x...)	#x
> +#define __stringify(x...)	__stringify_1(x)
> +
> +#endif	/* !__LINUX_STRINGIFY_H */



Amicalement,
-- 
Albert.


More information about the U-Boot mailing list