Array indexing and slicing

Luís Marques luismarques+spam at gmail.com
Tue Apr 4 09:50:16 PDT 2006


In article <e0tvba$1aav$1 at digitaldaemon.com>, novice2 says...
>i just want to say, IMHO, all changes in index/slicing syntax will change
>compiler only. not generated binary.

Actually I don't think that can be true. That would only be the case if the
indexes were defined at compilation time. Assuming positive indexes only, the
following code...

int index = get_int_from_user();
value = array[index];

could be translated into:

value = *(&array_contents + (index * element size));

If we allow negative indexes then that doesn't work. "index" is computed at
runtime so the code generated must change to allow that. At least that's the way
I see it.

About bounds checking, I didn't mean to imply it depends on the syntax.

Luís Marques



More information about the Digitalmars-d mailing list