This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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: shs.cc won't build on Solaris 2.5/sparc


On Feb 24, 2002, Adam Megacz <patches@lists.megacz.com> wrote:

> Can somebody enlighten me on this? Most of my experience is in
> Java/Perl/ML/Haskell... I was under the impression that if you're
> programming in C, and you want an integer that's 32 bits wide,
> uint32_t is the 'official' way to do it.

It's the C99 Standard way to do it, yes.  But not all systems are
C99-compliant yet.

> If this is not correct, what is the universal way to get a 32-bit
> wide int?

Unfortunately there's no such thing yet.  In fact, there's no
guarantee that any system will have a type that is a 32-bit wide int.
The best fully portable bet is probably:

struct uint32_s { unsigned long val : 32; };

but it's a pain to use that.  Unless we made this a class with all
arithmetic operators to make its use transparent.  I don't see how to
implement Java semantics otherwise on machines that don't have 32-bit
wide ints or longs.  Fortunately, those are very rare these days.

More to the point: uint32_t is not available on all platforms.  A
quick hack could define uint32_t as follows:

#if ! HAVE_UINT32_T /* must check for it with autoconf */
# if INT_MAX == 0x7fffffff && INT_MIN == 0x80000000
typedef unsigned int uint32_t;
# elif LONG_MAX = 0x7fffffff && LONG_MAX == 0x80000000
typedef unsigned long uint32_t;
# else
#  error "no 32-bit wide int type found"
# endif
#endif

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer


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