TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Array Indices: Start from 0 or 1?

26 pointsby pbnaidualmost 17 years ago

5 comments

byteCoderalmost 17 years ago
What is your name? Bill Gates<p>What is your quest? To conquer the world with Visual Basic.<p>At what index shall arrays start? One... no, zero... (arghhhhhhh.....)
评论 #233699 未加载
marcusalmost 17 years ago
Sadly my compromise of using 0.5 was flat out rejected.
pmjordanalmost 17 years ago
1-based arrays always make me think of the <i>Numerical Recipes</i> books, specifically the one using C. They jump through all sorts of hoops to have 1-based arrays:<p>- Array allocations are done using helper macros which invoke malloc and return a pointer to memory one element before the beginning of the array. (I'm pretty sure this is undefined behaviour according to the standard btw; it just happens that the format of pointers isn't data-dependent anymore these days)<p>- Array accesses are just as usual in C, except array[1] is the first element.<p>- Freeing memory is again wrapped in a macro to calculate the actual beginning of the array.<p>- Multidimensional arrays are layers of this crap.
评论 #234002 未加载
0x44almost 17 years ago
I think it would have been more appropriate to have linked directly to the XKCD comic in question instead of to blog spam.
评论 #233593 未加载
jamongkadalmost 17 years ago
I grew up thinking all array indices started at 0. That belief was held up until I met Lua of course.