bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stdint_.h vs intmax_t & uintmax_t


From: Mark D. Baushke
Subject: Re: stdint_.h vs intmax_t & uintmax_t
Date: Mon, 09 Jan 2006 23:24:21 -0800

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ben Pfaff <address@hidden> writes:

> I don't understand why ((size_t)-1) is considered C99 specific.

You are correct. It is not C99 specific. I was quoting the C99 standard
which Bruno referenced to be sure everyone was on the same page because
I could not find the old post that Bruno said he used that argument.

> Here is the equivalent paragraph from C90, numbered 3.2.1.2.(2)
> and .(3):
> 
[...elided...]
> 
> Thus, ((size_t)-1) is also the maximum value of size_t in C90.

This is true. 

Actually, all K&R C compiler implementations I have ever used let me use
a cast of -1 to the an unsigned type to get the maximum value of the
unsigned type, so that idiom has been around a long time. This included
ones compliment computers (e.g., Cray Y-MP) as well as the more common
twos compliment computers.

The real argument was the previous SIZE_MAX definition of (~(size_t)0)
which may NOT be the maximum value of a size_t if the width of an size_t
is narrower than int.

Bruno's alternative was to use ((size_t)~(size_t)0) which also will be
the maximum value of a size_t. As Bruno appears to prefer his idiom to
one that plays games with negative numbers in the definition of an
unsigned quantity and both have equivalent value, he committed the one
he liked as he is the maintainer for stdint_.h ... simple.

I hope this clears up your confusion.

        Enjoy!
        -- Mark
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (FreeBSD)

iD8DBQFDw2ElCg7APGsDnFERAvy6AJkBKwON8UOO7KHU2DptVViWRwSxSgCeLNAj
udhJ88j1VZeZTy6iCEucFE4=
=xket
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]