Your sizetype changes ...

Geoff Keating
Wed Mar 1 08:33:00 GMT 2000 (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)
  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 <>

More information about the Gcc-patches mailing list