This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Your sizetype changes ...
- To: kenner at vlsi1 dot ultra dot nyu dot edu (Richard Kenner)
- Subject: Re: Your sizetype changes ...
- From: Geoff Keating <geoffk at cygnus dot com>
- Date: 01 Mar 2000 08:32:15 -0800
- CC: gcc-patches at gcc dot gnu dot org
- References: <10003011019.AA20023@vlsi1.ultra.nyu.edu>
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>