Mark Gritter (markgritter) wrote,
Mark Gritter

Compiler writers aren't actually idiots

Occasionally I see 0-based indexing in programming languages justified in terms of efficiency of not having to subtract one when performing array lookups. For example, the C code
x = my_array[i]
translates into something like
movl (%ecx, %esi, 1), %eax
directly (where ecx holds my_array and esi holds 'i'), while presumably the Pascal equivalent
x := MyArray[i]
has to adjust 'i' by whatever the start index is (usually but not necessarily 1.) But there's no ironclad rule that says the implementation of 'MyArray' has to point at the actual address of the start of the array. The compiler writer can arrange things so that the exact same assembly is generated, can't she? (Except that Pascal performs bounds checking...)
  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.