"Fred Cisin (XenoSoft)" wrote:
> On Wed, 6 Feb 2002, John Chris Wren wrote:
> > Or it would possibly cause a segfault, since A can only be legally indexed
> > by 0..9. (This is assuming it didn't get optimized out).
>
> No. In C, that is actually NOT considered an error by the language! It's
> "bad form", but permitted by the language to use array notation to access
> memory locations that were NOT allocated to the array!
Thats because array notations are nothing more that pointer arithmetics. That is
why it is valid. It eventually becomes *(A + 10) which is *VALID* like any other
pointer operations in C. Of course, this may SEGV in certain systems. I remember
that * (A - 1) used to have the size of the array that was allocated! Dont know if
that
is true today....
Ram
--
,,,,
/'^'\
( o o )
-oOOO--(_)--OOOo-------------------------------------
| Ram Meenakshisundaram |
| Senior Software Engineer |
| OpenLink Financial Inc |
| .oooO Phone: (516) 227-6600 x267 |
| ( ) Oooo. Email: rmeenaks_at_olf.com |
---\ (----( )--------------------------------------
\_) ) /
(_/
Received on Wed Feb 06 2002 - 14:52:26 GMT