Christopher Smith wrote:
What does it matter whether the array was dynamically allocated?

Uhhhh, because the compiler doesn't know how big it is at runtime?

In things like Ada, the size of the array is stored with the array, and the compiler knows that. In C++, the size of the array is a separate variable, and if you say
for (i = 0; i < array_size; i++) myarray[i] = ...
the compiler has no way of knowing that array_size has anything to with the allocated size of myarray.

Of course, I'm happy to be shown how you'd write a class that checks array bounds where it would be possible for the compiler to optimize away the bounds checks in some cases.

If you have
for (i = 0; i < 5; i++) myarray[i] = ...
and the program text declares
int myarray[5];
or some such, then I would assume the compiler might be able to track that down.

--
  Darren New / San Diego, CA, USA (PST)
    His kernel fu is strong.
    He studied at the Shao Linux Temple.

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to