Click here to Skip to main content
15,914,642 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
AnswerRe: What to call array indexing starting at 0 vs. 1 ? Pin
Shameel19-Sep-13 5:09
professionalShameel19-Sep-13 5:09 
AnswerRe: What to call array indexing starting at 0 vs. 1 ? Pin
Ravi Bhavnani19-Sep-13 6:10
professionalRavi Bhavnani19-Sep-13 6:10 
AnswerRe: What to call array indexing starting at 0 vs. 1 ? Pin
CPallini19-Sep-13 7:33
mveCPallini19-Sep-13 7:33 
AnswerRe: What to call array indexing starting at 0 vs. 1 ? Pin
BillWoodruff19-Sep-13 20:13
professionalBillWoodruff19-Sep-13 20:13 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
pkfox19-Sep-13 20:52
professionalpkfox19-Sep-13 20:52 
AnswerRe: What to call array indexing starting at 0 vs. 1 ? Pin
ExcellentOrg19-Sep-13 21:14
ExcellentOrg19-Sep-13 21:14 
AnswerRe: What to call array indexing starting at 0 vs. 1 ? Pin
daniel_bingamon20-Sep-13 0:59
daniel_bingamon20-Sep-13 0:59 
AnswerRe: What to call array indexing starting at 0 vs. 1 ? Pin
kalberts20-Sep-13 1:36
kalberts20-Sep-13 1:36 
So you have never been programming Pascal.
As others have pointed out, in Pascal you set both the lower and upper index limits. (Furthermore, indexes may be any scalar type, such as an enumeration value. Enums are NOT names of integers in Pascal, but distinct value domains.)
You probably confused Pascal with Fortran, where array indexes start at 1.

I never understood this fascination for low-level programming in high-level languages! Say, if my table contains data for the years 1960 to 2020, why shouldn't I address (index) the elements with values from 1960 to 2020? Why would I want to define an index base as a separate constant and for every indexing operation subtract this base from the "real" selector value to get to the right index? Calculating addresses is the job of the compiler (and linker), isn't it? That's why we use a high level language compiler!

Having to subtract some base index value is like abandoning struct (/record) mechanisms and decalre the variable as a byte array, field names being offsets into the array. That gives you full control over packing and that kind of things, doesn't it? Great! Well, we do that in assembler, and it works. We can even do it in machine independent assembler, aka "C".

That's what we called C when it appeared, "machine independent assembler". I had my first university level programming education in Pascal, and we saw C as a great step backwards for modelling problem domain concepts. I still do.

Some languages, such as C#, allows you to define the semantics of the [] acessor for your own data types, so that the user of your class may index by values from 1960 to 2020. But you have to do a lot of programming to achieve this, and although I haven't checked, I am quite sure that the compiler isn't smart enough to reduce your accessor function to a simple subtraction of a base index value, the way the Pascal compiler could (not requiring any sort of programming from you). Technology isn't always moving in the forwards direction!
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
Sentenryu20-Sep-13 2:24
Sentenryu20-Sep-13 2:24 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
kalberts20-Sep-13 3:22
kalberts20-Sep-13 3:22 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
Sentenryu20-Sep-13 3:41
Sentenryu20-Sep-13 3:41 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
kalberts20-Sep-13 4:12
kalberts20-Sep-13 4:12 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
englebart20-Sep-13 3:18
professionalenglebart20-Sep-13 3:18 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
kalberts20-Sep-13 3:25
kalberts20-Sep-13 3:25 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
PIEBALDconsult23-Sep-13 4:03
mvePIEBALDconsult23-Sep-13 4:03 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
Michael Waters23-Sep-13 5:39
Michael Waters23-Sep-13 5:39 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
kalberts24-Sep-13 23:05
kalberts24-Sep-13 23:05 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
Michael Waters25-Sep-13 3:28
Michael Waters25-Sep-13 3:28 
AnswerRe: What to call array indexing starting at 0 vs. 1 ? Pin
englebart20-Sep-13 3:34
professionalenglebart20-Sep-13 3:34 
AnswerRe: What to call array indexing starting at 0 vs. 1 ? Pin
etkid8420-Sep-13 4:03
etkid8420-Sep-13 4:03 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
Michael Waters23-Sep-13 5:41
Michael Waters23-Sep-13 5:41 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
kalberts25-Sep-13 1:25
kalberts25-Sep-13 1:25 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
Michael Waters25-Sep-13 3:37
Michael Waters25-Sep-13 3:37 
AnswerRe: What to call array indexing starting at 0 vs. 1 ? Pin
RefugeeFromSlashDot20-Sep-13 5:21
RefugeeFromSlashDot20-Sep-13 5:21 
GeneralRe: What to call array indexing starting at 0 vs. 1 ? Pin
kalberts25-Sep-13 0:44
kalberts25-Sep-13 0:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.