PATCH: BPs & cleanups for ARRAY_SIZE
Wed Aug 23 18:10:00 GMT 2000
> Cc: Greg McGary <firstname.lastname@example.org>, Raja R Harinath <email@example.com>,
> From: Alexandre Oliva <firstname.lastname@example.org>
> Organization: GCC Team, Red Hat
> Date: 23 Aug 2000 19:06:38 -0300
> On Aug 23, 2000, Geoff Keating <email@example.com> wrote:
> > You can access the bytes of an object with a char*, but you can't
> > exceed the bounds of the object you're accessing.
> But then, is the object I'm accessing the whole multi-dimensional
> array or just one of its sub-arrays? And then, assuming it works for
It depends on how you got the char*. If you got it from a pointer to
the whole array, then the char* is a pointer to the whole array,
otherwise not :-).
You can easily tell where the char* came from; if you have
(char *)&t // can be used to access all of t, say 1600 bytes
(char *)&(t) // can only be used to access t, say 80 bytes
(char *)&(t) // can only be used to access t, say 4 bytes.
It seems a bit weird when you look at toy examples like this, but
suppose you had a procedure:
void something(int param);
then it's very helpful for you to be able to say
and have bounds checking catch it if it tries to access, say, any part
> char*, couldn't I use an int* to iterate over a multi-dimensional
> array of ints? Why should the bounds apply to the inner array,
> instead of the whole array. As long as I'm iterating within the same
> multi-dimensional array object, it should be fine, shouldn't it?
Not if someone is doing bounds checking. The whole point of that
language is to let compilers/runtimes/hardware do bounds checking.
- Geoffrey Keating <firstname.lastname@example.org>
More information about the Gcc-patches