LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-06-2015, 03:53 PM   #16
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897

Quote:
Originally Posted by sundialsvcs View Post
...or an enumerated-type such as color. Pascal, for example ...
I'd forgotten that. I'm sure, back in the day, I'd thought it was cute, but now I am far less sure.

Anyway, it is an interesting discussion; I'm not sure that there much of an efficiency argument for it, given that you can use the preprocessor to re-base the indexing, and the overhead in doing that isn't much and it is preprocessor overhead rather than run-time overhead. Feels wrong, though.
 
Old 07-07-2015, 04:59 AM   #17
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by sundialsvcs View Post
Prior to that, projects [i](e.g. "Multics" ... yes, "Unix = pun intended") were written very-substantially in assembly language.
Multics had a smaller fraction assembly than Unix. It was written almost entirely in a higher level language than C (abstracted further from the machine behavior and less efficient).

Multics being "prior" to Unix is questionable. Multics was under development and not yet at the level of a usable OS from before the idea of Unix was even conceived until after Unix was a usable OS. So the Multics project was certainly underway long before Unix, but Unix was a usable OS before Multics was.

Both borrowed most of their key concepts from ITS, much of which was written in B. But both Multics and Unix took the idea of limiting the assembler portion of the OS much further than ITS did.
 
1 members found this post helpful.
Old 07-07-2015, 07:51 AM   #18
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
As far as why the first array index is zero, it is in how the C language was defined.

I have an ancient "The C Programming Language" by K&R and right in the chapter about arrays it distinctly says "Array subscripts always start at zero in C, so the elements are ndigit[0], ndigit[1], ..."

Also as said by johnsfine, arrays are constructed to be related to pointers. This is highlighted in what used to be chapter 5, 5.3 Pointers and Arrays where they discuss [0] is related to the first pointer offset in memory, with respect to the array.

It is a convenience that the creators of the language chose, which also has a parallelism with pointer offsets and therefore is an extremely helpful, as well as natural, convenience.

As you can see, the definitions of some other languages use initial array indexes of 1 versus 0.
 
Old 07-07-2015, 10:42 AM   #19
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Quote:
Originally Posted by johnsfine View Post
Multics had a smaller fraction assembly than Unix. It was written almost entirely in a higher level language than C (abstracted further from the machine behavior and less efficient).

Multics being "prior" to Unix is questionable. Multics was under development and not yet at the level of a usable OS from before the idea of Unix was even conceived until after Unix was a usable OS. So the Multics project was certainly underway long before Unix, but Unix was a usable OS before Multics was.

Both borrowed most of their key concepts from ITS, much of which was written in B. But both Multics and Unix took the idea of limiting the assembler portion of the OS much further than ITS did.
True. My recollection of history was much poorer than I thought.
 
Old 07-07-2015, 10:44 AM   #20
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Quote:
Originally Posted by salasi View Post
I'd forgotten that. I'm sure, back in the day, I'd thought it was cute, but now I am far less sure.

Anyway, it is an interesting discussion; I'm not sure that there much of an efficiency argument for it, given that you can use the preprocessor to re-base the indexing, and the overhead in doing that isn't much and it is preprocessor overhead rather than run-time overhead. Feels wrong, though.
Enumerated types count-up from zero, but even if they did not, the cost is negligible.
 
Old 07-12-2015, 06:37 PM   #21
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally Posted by johnsfine View Post
Multics had a smaller fraction assembly than Unix. It was written almost entirely in a higher level language than C (abstracted further from the machine behavior and less efficient).

Multics being "prior" to Unix is questionable. Multics was under development and not yet at the level of a usable OS from before the idea of Unix was even conceived until after Unix was a usable OS. So the Multics project was certainly underway long before Unix, but Unix was a usable OS before Multics was.

Both borrowed most of their key concepts from ITS, much of which was written in B. But both Multics and Unix took the idea of limiting the assembler portion of the OS much further than ITS did.
Actually, the "prior" is, I think, conceptually unquestionable: The Multics development at M.I.T. was a joint project of several companies and the university. AT&T was one of those companies, and Kernighan and Ritchie were, I believe, part of the Multics development team that was removed when AT&T decided to withdraw from the project. They (K&R) were then assigned to the group developing text processing tools for AT&T. (Have you ever wondered why the UNIX base tool kit is so heavy on string and text tools?) To make their life easier, they upgraded the B (or, maybe, it was BCPL) macro set to include variable types, etc., and called the resulting macro set C. Then, based on what they'd learned from the Multics project, they put together a "stripped-down" OS that they called (in an obvious pun) UNIX.

Last edited by PTrenholme; 07-12-2015 at 06:38 PM.
 
Old 07-20-2015, 12:16 PM   #22
ron7000
Member
 
Registered: Nov 2007
Location: CT
Posts: 248

Rep: Reputation: 26
Quote:
Originally Posted by findnerd2 View Post
I was trying to work with array in c language and wondered that the base index of array does not start with other than zero...
because it's an offset from a starting memory address, not an index.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] use array index as file name rbees Programming 23 03-27-2015 07:58 AM
[SOLVED] How to find the index of bash array jags1984 Linux - Newbie 2 01-20-2014 12:06 AM
Decimal in array index micyew Programming 9 07-10-2012 09:28 AM
Perl: printing array's index and value craig467 Programming 8 08-30-2006 03:50 PM
index of an element in the array ? thelonius Programming 1 09-24-2005 12:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration