tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] casting bug?


From: Dave Dodge
Subject: Re: [Tinycc-devel] casting bug?
Date: Tue, 12 Jul 2005 16:49:26 -0400
User-agent: Mutt/1.4.2i

On Tue, Jul 12, 2005 at 04:23:53PM +0200, Felix Nawothnig wrote:
> It also guarantees that sizeof(char) <= sizeof(short) <= sizeof(int) <= 
> sizeof(long). (again I guess ISO C99 adds <= sizeof(long long))

It's a subtle point, but I don't think C99 actually guarantees this.
Instead it guarantees that the range of a smaller type is a subset of
the range of a larger type.  Where "smaller" and "larger" here refer
to the "integer conversion rank" of the type.

So while SHORT_MAX must be less than or equal to INT_MAX,
sizeof(short) can be larger than sizeof(int).  This is because C99
adds the concept of "padding bits" in an integer which do not
contribute to the value.  I think you could have a conforming
implementation where:

  short = 1 sign bit + 15 value bits + some padding bits
  int = 1 sign bit + 15 value bits + no padding bits

I doubt someone would actually implement this sort of thing, but I'm
pretty sure the standard does allow it.  There almost certainly are
platforms that use padding bits in some way, since otherwise there
wouldn't be much need to add the concept to the standard.

                                                  -Dave Dodge




reply via email to

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