[U-Boot] [PATCH 4/7] Check if compiler-provided <stdint.h> and <inttypes.h> are available if CONFIG_USE_STDINT=y (MAD)
Masahiro Yamada
yamada.m at jp.panasonic.com
Wed Dec 24 09:44:03 CET 2014
Hi Simon,
On Mon, 22 Dec 2014 21:46:26 -0700
Simon Glass <sjg at chromium.org> wrote:
> 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?
According to this question, I am afraid you are not understanding <inttypes.h> very well.
Maybe is this page useful?
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/inttypes.h.html
My commit description has also answered your question:
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.
Best Regards
Masahiro Yamada
More information about the U-Boot
mailing list