This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: __PRIPTR for 32-bit archs


On Feb  6 11:40, Corinna Vinschen wrote:
> Hi,
> 
> On Feb  5 11:30, Kornilios Kourtis wrote:
> > Hi,
> > 
> > We are trying to use newlib in the Barrelfish research OS. Maybe I'm
> > missing something, but I think that the current definition of __PRIPTR()
> > in libc/include/inttypes.h is not correct for 32-bit archs.
> > 
> > I believe this fixes it:
> > [...]
> That wouldn't work for LLP64 systems, afaics.  What about this?  It
> prefers using plain int over long long if the pointer size matches int
> size.  Only if that doesn't fit *and* __have_longlong64 is defined, we
> use long long:
> 
>   #if __have_long64
>   # define __PRIPTR(x) __STRINGIFY(l##x)
>   # define __SCNPTR(x) __STRINGIFY(l##x)
>   #elif PTRDIFF_MAX <= __STDINT_EXP(INT_MAX) || !defined(__have_longlong64)
>   # define __PRIPTR(x) __STRINGIFY(x)
>   # define __SCNPTR(x) __STRINGIFY(x)
>   #else
>   # define __PRIPTR(x) __STRINGIFY(ll##x)
>   # define __SCNPTR(x) __STRINGIFY(ll##x)
>   #endif

Hang on, that wouldn't work either for systems with sizeof(int) == 2 and
sizeof (long) == sizeof (void*) == 4.  One example is old default m68k
or current XStormy16 with -m32bit-pointers.

I think the right thing to do is to rely on the pointer size in relation
to the base types only, in the order int -> long -> long long.  If long long
is not defined, use long, like this:

  #if __STDINT_EXP(PTRDIFF_MAX) <= __STDINT_EXP(INT_MAX)
  # define __PRIPTR(x) __STRINGIFY(x)
  # define __SCNPTR(x) __STRINGIFY(x)
  #elif __STDINT_EXP(PTRDIFF_MAX) <= __STDINT_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

Comments?


Corinna

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]