public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* inttypes.h bug leads to inconsistent warnings cross platform
@ 2014-09-05 14:37 Joel Sherrill
  2014-09-08  6:14 ` Sebastian Huber
  2014-09-10 19:09 ` Joel Sherrill
  0 siblings, 2 replies; 12+ messages in thread
From: Joel Sherrill @ 2014-09-05 14:37 UTC (permalink / raw)
  To: newlib

Hi

This code will compile warning free on some targets but not
on others. This issue should exist on all targets base on the
CPU architecture as shown below.

#include <stdio.h>
#include <inttypes.h>

void f( uintptr_t p )
{
  printf( "Value = %" PRIuPTR "\n", p );
}

This is a list of warning/no warning for every RTEMS target
that compiles on the head.

=== arm-rtems4.11-gcc - no warning
=== bfin-rtems4.11-gcc - warning
=== i386-rtems4.11-gcc - warning
=== lm32-rtems4.11-gcc - no warning
=== m68k-rtems4.11-gcc - warning
=== nios2-rtems4.11-gcc - no warning
=== or1k-rtems4.11-gcc - warning
=== powerpc-rtems4.11-gcc - no warning
=== sh-rtems4.11-gcc - no warning
=== sparc64-rtems4.11-gcc - no warning
=== sparc-rtems4.11-gcc - no warning
=== v850-rtems4.11-gcc - no warning

I have tracked this down to newlib's inttypes.h does not detect
when gcc defines integer pointer types to long. PRIuPTR turns
into "u" not "ul".

$ or1k-rtems4.11-gcc -dM -E - </dev/null | grep INTPTR_T
#define __INTPTR_TYPE__ long int
#define __UINTPTR_TYPE__ long unsigned int
$ arm-rtems4.11-gcc -dM -E - </dev/null | grep INTPTR_T
#define __INTPTR_TYPE__ int
#define __UINTPTR_TYPE__ unsigned int

On the above two targets __PTRDIFF_TYPE__ is the same.

The code in inttypes.h in question is:

#if PTRDIFF_MAX <= __INTTYPES_EXP(INT_MAX)
# define __PRIPTR(x) __STRINGIFY(x)
# define __SCNPTR(x) __STRINGIFY(x)
#elif PTRDIFF_MAX <= __INTTYPES_EXP(LONG_MAX) || !defined(__have_longlong64)
# define __PRIPTR(x) __STRINGIFY(l##x)
# define __SCNPTR(x) __STRINGIFY(l##x)
#else
# define __PRIPTR(x) __STRINGIFY(ll##x)
# define __SCNPTR(x) __STRINGIFY(ll##x)
#endif

Any thoughts on how to detect when it should use
"ul" for long uinptr_t instead of "u" for targets with
int uintptr_t?

I don't see any related variables that differ in the predefined
CPP macros except the actual type.

Thanks.

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill@OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-09-11 16:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-05 14:37 inttypes.h bug leads to inconsistent warnings cross platform Joel Sherrill
2014-09-08  6:14 ` Sebastian Huber
2014-09-08  8:12   ` Joel Sherrill
2014-09-08  8:17     ` Sebastian Huber
2014-09-10 19:09 ` Joel Sherrill
2014-09-10 20:25   ` Joseph S. Myers
2014-09-10 20:47     ` Joel Sherrill
2014-09-10 20:53   ` Jeff Johnston
2014-09-10 20:57     ` Joel Sherrill
2014-09-10 21:13       ` Jeff Johnston
2014-09-11  3:39         ` Eric Blake
2014-09-11 16:35           ` Jeff Johnston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).