This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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

Re: Your sizetype changes ...



kenner@vlsi1.ultra.nyu.edu (Richard Kenner) writes:

>     *Anything* that is legal to do with a size_t is also legal to do with
>     an unsigned int, and vice versa.  So, this comment:
> 
> No.  The case is (x * 40) / 20.  If x is a normal unsigned type, you
> can't convert this to x*2 because the x*40 might have overflowed.  But
> if it's an actual sizetype, you can.

You mean, "if it's an actual size".

It's not true that

size_t foo(size_t x)
{
  return (x * 40) / 20;
}

is equivalent to 

size_t foo(size_t x)
{
  return x * 2;
}

because I can write

int main(void)
{
  if (foo ((size_t)-3) == (size_t)-6)
    abort();
  return 0;
}

and expect that it will never abort in ISO C.

In fact, it's not even always true that

sizeof(struct foo) * 40 / 20

is equivalent to 

sizeof(struct foo) * 2

because 'struct foo' may be large.  It is 'x * 40' that must be the
size of something, and IMHO it's easier to specify this by limiting
the range of 'x' (which I believe we have the support to do).

-- 
- Geoffrey Keating <geoffk@cygnus.com>

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