Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: i think i found |
| Date | 2012-03-11 13:06 -0700 |
| Organization | None to speak of |
| Message-ID | <lnipiaewcj.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> |
jgk@panix.com (Joe keane) writes:
> In article <ea3cda64-a914-4f34-ba2a-59df5fb9fc93@m13g2000yqi.googlegroups.com>,
> Barry Schwarz <schwarz45@yahoo.com> wrote:
>>Since your sample code does not have any arrays of arrays, we have no
>>idea what your question is.
>
> OK
>
> int f(int x)
> {
> int a[2][2];
> int *p;
>
> p = &a[0][0];
> *p = 1;
> p += 2;
> *p = 2;
> --p;
> *p = 3;
> p += 2;
> *p = 4;
> /* printf(...); */
> return 0;
> }
Great, you've posted some more code. Did you want to say something
about it? Your subject header is "i think i found". What exactly do
you think you've found?
I'm sure the point you're making is clear to you, but you're not
conveying it well to the rest of us.
As for the code you posted, its behavior is undefined. "p" is an "int*"
that's initialized to point to element 0 of a 2-element array a[0]
(which happens to be an element of a larger array). "p += 2" causes it
to point just past the last element of the array a[0], which is ok. But
the "*p = 2;" assigns a value past the end of that array, which has
undefined behavior.
N1570 section J.2 has a (non-normative) list of undefined behaviors, one
of which is:
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).
So what was your question?
--
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
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