PATCH: BPs & cleanups for ARRAY_SIZE

Geoff Keating
Wed Aug 23 18:10:00 GMT 2000

> Cc: Greg McGary <>, Raja R Harinath <>,
> From: Alexandre Oliva <>
> Organization: GCC Team, Red Hat
> Date: 23 Aug 2000 19:06:38 -0300

> On Aug 23, 2000, Geoff Keating <> 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

int t[10][20];


(char *)&t // can be used to access all of t, say 1600 bytes
(char *)&(t[1]) // can only be used to access t[1], say 80 bytes
(char *)&(t[1][1]) // can only be used to access t[1][1], 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[20]);

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
of t[5].

> 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 <>

More information about the Gcc-patches mailing list