What to call array indexing starting at 0 vs. 1 ?
-
Is there a technical term to say if an array starts at index 0 (e.g. C/C++) or 1 (e.g. pascal) ? Is it simply "0-based array" and "1 based array" ? Thanks.
I'd rather be phishing!
Standard & Mutant ? why was Pascal 1 based? anyone know if Delphi is has one based arrays as it might explain some error generated by a test application I have to use?
-
Meh! Real men code with edlin.
speramus in juniperus
-
Is there a technical term to say if an array starts at index 0 (e.g. C/C++) or 1 (e.g. pascal) ? Is it simply "0-based array" and "1 based array" ? Thanks.
I'd rather be phishing!
-
Is there a technical term to say if an array starts at index 0 (e.g. C/C++) or 1 (e.g. pascal) ? Is it simply "0-based array" and "1 based array" ? Thanks.
I'd rather be phishing!
Yes, zero-based and one-based indexing are correct terms. /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Standard & Mutant ? why was Pascal 1 based? anyone know if Delphi is has one based arrays as it might explain some error generated by a test application I have to use?
glennPattonWork wrote:
why was Pascal 1 based?
It's not, neither is Object-Pascal (Delphi). The type-definition of an array would contain the start-index and the end-index. One would use 0, obviously. Dynamic arrays start at 0. Even BASIC[^] starts at 0.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
Meh! Real men code with edlin.
speramus in juniperus
Real men code by staring intently at their powered-off, disconnected hard drive and visualize the magnetic bits into their proper alignment.
Software Zen:
delete this;
-
Meh! Real men code with edlin.
speramus in juniperus
-
Meh! Real men code with edlin.
speramus in juniperus
-
I believe the correct terms are right and wrong.
speramus in juniperus
-
Is there a technical term to say if an array starts at index 0 (e.g. C/C++) or 1 (e.g. pascal) ? Is it simply "0-based array" and "1 based array" ? Thanks.
I'd rather be phishing!
-
I only have seen that in the Intellisense popup of some .NET function. Intellisense is all the documentation that I need. :laugh:
-
Real men code with Emacs and vi.
We can’t stop here, this is bat country - Hunter S Thompson RIP
EDT
-
Is there a technical term to say if an array starts at index 0 (e.g. C/C++) or 1 (e.g. pascal) ? Is it simply "0-based array" and "1 based array" ? Thanks.
I'd rather be phishing!
(0) The one true path to direct epiphanic experience of ineffable ecstasy in emptiness. (1) The Mother of All Lies, the Deceiver, the Abomination which is the Canker that rots the Soul from within. bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
-
(0) The one true path to direct epiphanic experience of ineffable ecstasy in emptiness. (1) The Mother of All Lies, the Deceiver, the Abomination which is the Canker that rots the Soul from within. bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
-
Real men code with Emacs and vi.
We can’t stop here, this is bat country - Hunter S Thompson RIP
-
Is there a technical term to say if an array starts at index 0 (e.g. C/C++) or 1 (e.g. pascal) ? Is it simply "0-based array" and "1 based array" ? Thanks.
I'd rather be phishing!
Looks like you are on a journey of self discovery, lad!!!. Keep going and you will discover the mysterious world of Big Endian and Little Endian. But Beware, Do not rest until you cross the Byte Boundary, Word Boundary and Double Word boundary. Beyond that you will start to see some faint light from the tower 64. ------------------ - Wizard of O1
-
I only have seen that in the Intellisense popup of some .NET function. Intellisense is all the documentation that I need. :laugh:
-
Meh! Real men code with edlin.
speramus in juniperus
sure ! I've use edlin on MS-DOS, e on OS/2, etc... but in the 80' :laugh: now, Notepad++ fits to my needs
If there is no solution, there is no problem !
-
Is there a technical term to say if an array starts at index 0 (e.g. C/C++) or 1 (e.g. pascal) ? Is it simply "0-based array" and "1 based array" ? Thanks.
I'd rather be phishing!
"0-based array" is called an "offset". "1-based array" could be called "displayable index"
-
Is there a technical term to say if an array starts at index 0 (e.g. C/C++) or 1 (e.g. pascal) ? Is it simply "0-based array" and "1 based array" ? Thanks.
I'd rather be phishing!
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!