[U-Boot] [PATCH 4/7] Check if compiler-provided <stdint.h> and <inttypes.h> are available if CONFIG_USE_STDINT=y (MAD)
Simon Glass
sjg at chromium.org
Tue Dec 23 05:46:26 CET 2014
Hi Masahiro,
On 22 December 2014 at 03:16, Masahiro Yamada <yamada.m at jp.panasonic.com> wrote:
> CONFIG_USE_STDINT was introduced to use compiler-provided types for
> fixed-width variables.
> This must be consistent everywhere to avoid warnings/errors
> including printf() and friends.
>
> Assume the code below
>
> uint32_t foo;
>
> printf("foo= %x\n", foo);
>
> If <stdint.h> is included, uint32_t is defined by the compiler.
> The code above only works on compilers that define "uint32_t"
> as "unsigned int". Actually there exist compilers that define
> "uint32_t" as "unsigned long".
>
> Going forward, to print out fixed-width variables, we always have
> to use PRIxN like this
>
> uint32_t foo;
>
> printf("foo= " PRIx32 "\n", foo);
>
> Notice,
>
> - Typedefs ( uint32_t, int32_t etc.) are provided by <stdint.h>
> - Printf formats ( PRIx32, PRId32 etc.) are provided by <inttypes.h>
>
> Also notice, it makes sense only when <stdint.h> and <inttypes.h> are provided by
> the same compiler.
> ^^^^^^^^^^^^^^^^^^
>
> Commit 4166ecb24 (Add some standard headers external code might need) added
> hard-coded include/inttypes.h.
> It provides hard-coded PRIx32 "x", but it does not make sense.
> Some compiler's <stdint.h> define "uint32_t" as "unsigned long"
> and expect the format string "lx" to print out "uint32_t" variable.
>
> This commit:
> - Adds scripts/gcc-have-stdint.sh to check if the compiler is
> providing both <stdint.h> and <inttypes.h>
>
> - Modifies config.mk to error-out if CONFIG_USE_STDINT is enabled,
> but <stdint.h> or <inttyps.h> is missing
>
> - Modifies the top Makefile to delete "-nostdinc" option and allow to
> include compiler-provided <inttypes.h>
>
> - Remove hard-coded include/inttypes.h
This patch looks good to me except that I don't understand why you are
removing inttypes.h? Where will the PRI defines come from? Or is it
because you are fixing things such that the defines are not needed
anymore?
>
> Signed-off-by: Masahiro Yamada <yamada.m at jp.panasonic.com>
> Cc: Gabe Black <gabeblack at chromium.org>
> Cc: Simon Glass <sjg at chromium.org>
> Cc: Bill Richardson <wfrichar at google.com>
> Cc: Tom Rini <trini at ti.com>
> ---
>
> Makefile | 2 +-
> config.mk | 12 ++
> include/inttypes.h | 287 ---------------------------------------------
> scripts/gcc-have-stdint.sh | 21 ++++
> 4 files changed, 34 insertions(+), 288 deletions(-)
> delete mode 100644 include/inttypes.h
> create mode 100755 scripts/gcc-have-stdint.sh
>
[snip]
Regards,
Simon
More information about the U-Boot
mailing list