[Top][All Lists]

[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

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
> and .(3):
> 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.

        -- Mark
Version: GnuPG v1.2.3 (FreeBSD)


reply via email to

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