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


Groups > comp.lang.c > #18715

Re: i think i found

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: i think i found
Date 2012-03-13 15:25 -0700
Organization None to speak of
Message-ID <lnk42ocf5l.fsf@nuthaus.mib.org> (permalink)
References <jje9kd$d14$1@reader1.panix.com> <ea3cda64-a914-4f34-ba2a-59df5fb9fc93@m13g2000yqi.googlegroups.com> <jjiupi$ehe$1@reader1.panix.com> <lnipiaewcj.fsf@nuthaus.mib.org> <jjoak2$qkr$1@reader1.panix.com>

Show all headers | View raw


jgk@panix.com (Joe keane) writes:
> In article <lnipiaewcj.fsf@nuthaus.mib.org>,
> Keith Thompson  <kst-u@mib.org> wrote:
>>    An array subscript is out of range, even if an object is apparently
>>    accessible with the given subscript (as in the lvalue expression
>>    a[1][7] given the declaration int a[4][5]) (6.5.6).
>
> I didn't use 'array subscript' at all!
>
> It is fine that in a "a[i][j]" syntax people can check both subsctipts
> rather than the offset.  But it's rather oblique about whether you can
> increment a 'int *' pointer, e.g. from &a[0][4] to &a[1][0].  It would
> be kind of sad if this didn't work right.  It doesn't overtly address
> the point.

The array subscript operation is defined in terms of pointer
arithmetic; E1[E2] is by definition identical to (*((E1)+(E2))).
It follows from that that your example's behavior is undefined.

In practice, it's likely to "work", but a compiler is free to generate
code assuming that the indices do not exceed the declared bounds of the
array.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


Thread

i think i found jgk@panix.com (Joe keane) - 2012-03-10 01:09 +0000
  Re: i think i found Ian Collins <ian-news@hotmail.com> - 2012-03-10 14:23 +1300
  Re: i think i found nick_keighley_nospam@hotmail.com - 2012-03-10 03:13 -0800
  Re: i think i found Barry Schwarz <schwarz45@yahoo.com> - 2012-03-10 09:17 -0800
    Re: i think i found pete <pfiland@mindspring.com> - 2012-03-10 19:22 -0500
      Re: i think i found James Kuyper <jameskuyper@verizon.net> - 2012-03-10 20:14 -0500
        Re: i think i found pete <pfiland@mindspring.com> - 2012-03-10 21:59 -0500
      Re: i think i found jgk@panix.com (Joe keane) - 2012-03-12 17:29 +0000
    Re: i think i found jgk@panix.com (Joe keane) - 2012-03-11 19:35 +0000
      Re: i think i found Keith Thompson <kst-u@mib.org> - 2012-03-11 13:06 -0700
        Re: i think i found jgk@panix.com (Joe keane) - 2012-03-13 20:27 +0000
          Re: i think i found Keith Thompson <kst-u@mib.org> - 2012-03-13 15:25 -0700
            Re: i think i found jgk@panix.com (Joe keane) - 2012-03-14 23:34 +0000
              Re: i think i found Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-03-14 20:38 -0400
              Re: i think i found Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-15 18:03 -0700
                Re: i think i found jgk@panix.com (Joe keane) - 2012-03-17 17:34 +0000
                Re: i think i found Keith Thompson <kst-u@mib.org> - 2012-03-17 18:02 -0700
                Re: i think i found jgk@panix.com (Joe keane) - 2012-03-19 15:41 +0000
                Re: i think i found Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-21 05:52 -0700

csiph-web