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


> -----Original Message-----
> From: newlib-owner@sourceware.org [mailto:newlib-owner@sourceware.org]
> On Behalf Of Eric Blake
> Sent: Wednesday, February 20, 2013 5:16 PM
> To: newlib@sourceware.org
> Subject: Re: [PATCH 64bit] ssize_t
> 
> On 02/20/2013 08:17 AM, Corinna Vinschen wrote:
> 
> >> GCC requires exact symmetry of types between ssize_t and size_t.
> >> I.e. checking for sizes of types is not sufficient for [s]size_t.
> >
> > Do you have a code suggestion then?  GCC doesn't define ssize_t by
> > itself, nor in stddef.h except for BeOS.  And the only predefines
> > helping us are
> >
> >   #define __SIZE_MAX__ 18446744073709551615UL
> >   #define __SIZEOF_INT__ 4
> >   #define __SIZEOF_LONG__ 8
> >   #define __SIZEOF_SIZE_T__ 8
> >   #define __SIZE_TYPE__ long unsigned int
> 
> There's the key.  But how to make gcc tell us the corresponding signed
> type?  Can we write something that relies on
> __builtin_types_compatible_p?
> 

Pardon me, but would an approach similar to the following work?

# include <limits.h>

typedef int
# if USHRT_MAX == __SIZE_MAX__
	short
# elif UINT_MAX == __SIZE_MAX__
	
# elif ULONG_MAX == __SIZE_MAX__
	long
# elif define ULLONG_MAX && ULLONG_MAX == __SIZE_MAX__
	long long
# else
#	error	Do not know how to define ssize_t
# endif
	ssize_t;


Regards,

Konrad Schwarz

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