This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: inttypes.h bug leads to inconsistent warnings cross platform
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Joel Sherrill <joel dot sherrill at oarcorp dot com>
- Cc: "newlib at sourceware dot org" <newlib at sourceware dot org>
- Date: Wed, 10 Sep 2014 20:25:14 +0000
- Subject: Re: inttypes.h bug leads to inconsistent warnings cross platform
- Authentication-results: sourceware.org; auth=none
- References: <5409CAAD dot 1030801 at oarcorp dot com> <5410A1D3 dot 4070106 at oarcorp dot com>
On Wed, 10 Sep 2014, Joel Sherrill wrote:
> Adding Joseph Myers since newlib-stdint.h appears to have
> originated with him.
Well - newlib-stdint.h was designed to replicate the logic that already
existed in newlib to define these types, which defined intptr_t to be the
same as ptrdiff_t, and uintptr_t to be the corresponding unsigned type
(normally the same as size_t).
> Does anyone have any ideas on how to address this? Is there some
> piece of info from gcc now to for inttypes.h to make the right
> selection? Or can gcc provide another cpp macro which would help?
GCC's predefines are intended for stdint.h, not for inttypes.h given
that's not required for freestanding implementations so GCC doesn't try to
provide it.
You could have a header varying depending on the architecture (or with
architecture conditionals) that embeds the logic about the choice of types
here. Or you could do some sort of hack along the lines of
#define signed +0
#define int +0
#define long +1
#if __INTPTR_TYPE__ == 2
/* long long */
#elif __INTPTR_TYPE__ == 1
/* long */
#elif __INTPTR_TYPE__ == 0
/* int */
#else
#error
#endif
#undef signed
#undef int
#undef long
to identify what type is being used (it's invalid to include a standard
header with any keywords defined as macros, so it's valid for such a
header to temporarily define such macros then undefine them).
--
Joseph S. Myers
joseph@codesourcery.com