[U-Boot] [PATCH] include: define bool type in a more portable way

Wolfgang Denk wd at denx.de
Mon Nov 18 17:28:56 CET 2013


Dear Masahiro Yamada,

In message <1384770105-32364-1-git-send-email-yamada.m at jp.panasonic.com> you wrote:
> Currently U-boot defins bool type by including <stdbool.h>
> rather than defining directly.
> But it does not work for some cross compilers.

Can you explain why this fails?

AFAICT, <stdbool.h> is a compiler provided header file, which is
mandatory by the C99 ISO standard. So if a compiler fails to work
using it, it looks as if the compiler was broken.

> In file included from /home/yamada/u-boot/arch/blackfin/include/asm/blackfin.h:13,
>                  from /home/yamada/u-boot/include/common.h:92,
>                  from cmd_test.c:17:
> /home/yamada/u-boot/arch/blackfin/include/asm/blackfin_local.h:54: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'bfin_os_log_check'

Which code does the compiler generate for line # 54:

	extern bool bfin_os_log_check(void);


> diff --git a/include/linux/stddef.h b/include/linux/stddef.h
> index c540f61..5893ec9 100644
> --- a/include/linux/stddef.h
> +++ b/include/linux/stddef.h
> @@ -12,6 +12,11 @@
>  #include <linux/types.h>
>  #endif
>  
> +enum {
> +	false	= 0,
> +	true	= 1
> +};
> +

This looks fishy to me.   Files that used to include <stdbool.h> do
not necessarily include <linux/stddef.h>, so they may now be missing
the definitions of "true" and "false".

For example, arch/arm/cpu/armv7/mx6/soc.c (which you touched above)
does not include <linux/stddef.h> ...

> diff --git a/include/linux/types.h b/include/linux/types.h
> index 9aebc4e..157e1ae 100644
> --- a/include/linux/types.h
> +++ b/include/linux/types.h
> @@ -3,7 +3,6 @@
>  
>  #include <linux/posix_types.h>
>  #include <asm/types.h>
> -#include <stdbool.h>
>  
>  #ifndef __KERNEL_STRICT_NAMES
>  
> @@ -18,6 +17,8 @@ typedef __kernel_daddr_t	daddr_t;
>  typedef __kernel_key_t		key_t;
>  typedef __kernel_suseconds_t	suseconds_t;
>  
> +typedef _Bool			bool;
> +
>  #ifdef __KERNEL__
>  typedef __kernel_uid32_t	uid_t;
>  typedef __kernel_gid32_t	gid_t;

I can't say that I'm happy with that.  I think we should first
understand the real cause of the problem.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Why can you only have two doors on a chicken coop? If it had four  it
would be a chicken sedan.


More information about the U-Boot mailing list