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: [PATCH 64bit] ssize_t


On Feb 20 18:16, Ralf Corsepius wrote:
> On 02/20/2013 05:06 PM, Corinna Vinschen wrote:
> >Unfortunately we're not living in an ideal world.  That said, I'm
> >willing to go with the obvious as I outlined above. Since size_t is
> >*likely* defined as int if int == long, and defined as long if int <
> >long, this should match most cases.  Oh, and then there are the
> >potential LLP64 systems which define sizeof size_t == sizeof long long.
> >An additional elif would catch that:
> >
> >#  if defined (__SIZEOF_INT__) && __SIZEOF_SIZE_T__ == __SIZEOF_INT__
> >typedef int ssize_t;
> >#  elif defined (__SIZEOF_LONG__) && __SIZEOF_SIZE_T__ == __SIZEOF_LONG__
> >typedef long ssize_t
> >#  else
> >typedef long long ssize_t;
> >#  endif
> 
> Sorry, I think, I did not communicate my point accurately.
> 
> Let me try again:
> 
> GCC doesn't apply a size-based logic to define size_t, but applies
> hard-coded predefined types for size_t, likely based on historic
> per-target conventions.
> 
> I.e. any type-size based logic will sometimes fail:
> 
> E.g. for targets with sizeof(size_t) == sizeof(int) == sizeof(long).
> on some targets GCC uses "typedef unsigned int size_t" and on other
> targets GCC uses "typedef unsigned long size_t".
> 
> Now, if you choose "typedef int ssize_t" on targets, which use
> "typedef long size_t", GCC will raise warnings related to fprintfs.

How is that different from what newlib did before, except that typedef
int ssize_t; is very certainly wrong on most 64 bit platforms.  I don't
remember any complaints or patches on this list related to this
behaviour.

What we have is a bad default which needs overriding via machine
dependent files.  The suggestion here is to define ssize_t a bit more
correct in most cases.  Given your above assessment, there appears to be
no 100% correct way anyway, even when using _WORDSIZE as Chris suggests.
Only exact target knowledge would do that.

So, from my POV, what we can do in sys/_types.h is  to provide a sane
default.  If this still doesn't match, add a target dependent file.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat


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