Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #76885

Re: just a curiosity about starting array indexing at 0 as opposed to 1

From BartC <bc@freeuk.com>
Newsgroups comp.lang.c
Subject Re: just a curiosity about starting array indexing at 0 as opposed to 1
Date 2015-11-22 16:22 +0000
Organization A noiseless patient Spider
Message-ID <n2spve$tpd$1@dont-email.me> (permalink)
References <2df732fe-b6ed-47a2-b61d-30d45a7cab91@googlegroups.com> <74bfe663-fc00-4e6b-84fa-ce18502fa8e7@googlegroups.com> <28721e81-a482-4ad2-a28d-adbc69330e54@googlegroups.com> <b238b932-2e50-4aef-bbde-58481ee4f099@googlegroups.com>

Show all headers | View raw


On 22/11/2015 15:20, supercat@casperkitty.com wrote:
> On Sunday, November 22, 2015 at 2:16:05 AM UTC-6, Malcolm McLean wrote:
>> Except that you use the index to refer to the stretch between milestone
>> 3 and milestone 4. So is the lorry at the milestone, or between
>> milestones?
>
> Given
>    int arr[100];
>    uint32_t *p = arr[3];
>    uint8_t  *q = arr[3];
>
>    *p = 1234;
>    *q = 6;
>
> Since each "int" is four miles long, p identifies mile marker 12 [four
> times three].  So does q.  *p identifies a 4-mile stretch starting at mile
> 12, while *q identifies a 1-mile stretch starting at the same point.

Here you're viewing the arrays in 'fence-post' mode.

Fence-posts are numbered 0, 1, 2, 3 which can represent the distance of 
the post from the origin.

The panels represent array panels and are most sensibly numbered 1, 2, 3.

You can talk of relative offsets and distances with the posts because a 
post is thin, a single point, but a panel is large and you don't know if 
you're talking about the left, right or some arbitrary point in the middle.

Both schemes have their uses. But for ordinary use of an array (and if 
you try and drag it away from defining it in terms of pointers), 1-based 
arrays can make sense.

-- 
Bartc

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

just a curiosity about starting array indexing at 0 as opposed to 1 G G <gdotone@gmail.com> - 2015-11-21 18:50 -0800
  Re: just a curiosity about starting array indexing at 0 as opposed to 1 supercat@casperkitty.com - 2015-11-21 19:31 -0800
    Re: just a curiosity about starting array indexing at 0 as opposed to 1 Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-22 00:15 -0800
      Re: just a curiosity about starting array indexing at 0 as opposed to 1 supercat@casperkitty.com - 2015-11-22 07:20 -0800
        Re: just a curiosity about starting array indexing at 0 as opposed to 1 BartC <bc@freeuk.com> - 2015-11-22 16:22 +0000
          Re: just a curiosity about starting array indexing at 0 as opposed to 1 supercat@casperkitty.com - 2015-11-22 08:44 -0800
    Re: just a curiosity about starting array indexing at 0 as opposed to 1 Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-22 10:37 -0500
      Re: just a curiosity about starting array indexing at 0 as opposed to 1 BartC <bc@freeuk.com> - 2015-11-22 15:50 +0000
        Re: just a curiosity about starting array indexing at 0 as opposed to 1 Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-22 11:02 -0500
          Re: just a curiosity about starting array indexing at 0 as opposed to 1 BartC <bc@freeuk.com> - 2015-11-22 16:15 +0000
  Re: just a curiosity about starting array indexing at 0 as opposed to 1 Ian Collins <ian-news@hotmail.com> - 2015-11-22 16:42 +1300
    Re: just a curiosity about starting array indexing at 0 as opposed to 1 G G <gdotone@gmail.com> - 2015-11-21 19:55 -0800
    Re: just a curiosity about starting array indexing at 0 as opposed to 1 Keith Thompson <kst-u@mib.org> - 2015-11-23 11:01 -0800
      Re: just a curiosity about starting array indexing at 0 as opposed to 1 BartC <bc@freeuk.com> - 2015-11-23 19:18 +0000
        Re: just a curiosity about starting array indexing at 0 as opposed to 1 Keith Thompson <kst-u@mib.org> - 2015-11-23 11:26 -0800
          Re: just a curiosity about starting array indexing at 0 as opposed to 1 glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-23 22:54 +0000
            Re: just a curiosity about starting array indexing at 0 as opposed to 1 Robert Wessel <robertwessel2@yahoo.com> - 2015-11-23 18:37 -0600
              Re: just a curiosity about starting array indexing at 0 as opposed to 1 raltbos@xs4all.nl (Richard Bos) - 2015-11-24 15:22 +0000
      Re: just a curiosity about starting array indexing at 0 as opposed to 1 raltbos@xs4all.nl (Richard Bos) - 2015-11-24 15:13 +0000
  Re: just a curiosity about starting array indexing at 0 as opposed to 1 Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-22 01:21 -0500
    Re: just a curiosity about starting array indexing at 0 as opposed to 1 glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-22 15:00 +0000
      Re: just a curiosity about starting array indexing at 0 as opposed to 1 Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-22 10:15 -0500
        Re: just a curiosity about starting array indexing at 0 as opposed to 1 glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-23 13:47 +0000
          Re: just a curiosity about starting array indexing at 0 as opposed to 1 BartC <bc@freeuk.com> - 2015-11-23 14:50 +0000
            Re: just a curiosity about starting array indexing at 0 as opposed to 1 Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-23 12:01 -0500
              Re: just a curiosity about starting array indexing at 0 as opposed to 1 James Kuyper <jameskuyper@verizon.net> - 2015-11-23 12:12 -0500
                Re: just a curiosity about starting array indexing at 0 as opposed to 1 Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-23 12:57 -0500
            Re: just a curiosity about starting array indexing at 0 as opposed to 1 glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-23 23:08 +0000
          Re: just a curiosity about starting array indexing at 0 as opposed to 1 bert <bert.hutchings@btinternet.com> - 2015-11-23 08:52 -0800
      Re: just a curiosity about starting array indexing at 0 as opposed to 1 BartC <bc@freeuk.com> - 2015-11-22 15:42 +0000
        Re: just a curiosity about starting array indexing at 0 as opposed to 1 Keith Thompson <kst-u@mib.org> - 2015-11-22 12:36 -0800
        Re: just a curiosity about starting array indexing at 0 as opposed to 1 BartC <bc@freeuk.com> - 2015-11-22 21:06 +0000
  Re: just a curiosity about starting array indexing at 0 as opposed to 1 BartC <bc@freeuk.com> - 2015-11-22 10:28 +0000
    Re: just a curiosity about starting array indexing at 0 as opposed to 1 gazelle@shell.xmission.com (Kenny McCormack) - 2015-11-22 12:04 +0000
  Re: just a curiosity about starting array indexing at 0 as opposed to 1 Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-22 11:24 +0000
    Re: just a curiosity about starting array indexing at 0 as opposed to 1 G G <gdotone@gmail.com> - 2015-11-22 04:29 -0800
  Re: just a curiosity about starting array indexing at 0 as opposed to 1 see.my.homepage@gmail.com - 2015-11-22 04:54 -0800
    Re: just a curiosity about starting array indexing at 0 as opposed to 1 BartC <bc@freeuk.com> - 2015-11-22 13:43 +0000
    Re: just a curiosity about starting array indexing at 0 as opposed to 1 James Kuyper <jameskuyper@verizon.net> - 2015-11-22 11:04 -0500
  Re: just a curiosity about starting array indexing at 0 as opposed to 1 Jens Stuckelberger <Jens_Stuckelberger@nowhere.net> - 2015-11-22 15:29 +0000
  Re: just a curiosity about starting array indexing at 0 as opposed to 1 Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-22 14:06 -0800
  Re: just a curiosity about starting array indexing at 0 as opposed to 1 John Bode <jfbode1029@gmail.com> - 2015-11-23 07:49 -0800

csiph-web