Re: decrement past beginning is valid?
From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: Fri, 05 Nov 2004 03:32:10 GMT
"Watson Davis" <firstname.lastname@example.org> wrote in message
> Francis Glassborow <email@example.com> wrote in
> > In article <Xns959756278EEC1thepencilneckyahooco@22.214.171.124>,
> > Watson Davis <firstname.lastname@example.org> writes
> >>Pedro Graca <email@example.com> wrote in
> >>> I know that incrementing a pointer one past the end of the array is
> >>> valid (as long as I don't dereference it).
> >>> Is it valid to decrement before beginning of array?
> >>Sure. It's just a pointer and you can pretty much increment and
> >>decrement that thing all over the place without a problem. Well... if
> >>you ASSIGN something to the wrong place you can create some pretty
> >>magnificent problems...
> > No, creating an address that is not owned by your process can and does
> > cause your program to abort on some platforms. The dispensation for
> > one-past-the-end is exactly a requirement on compilers for such
> > platforms to ensure that that address is owned by the process and so
> > does not cause the program to abort.
> You are misinterpreting my point.
I think he's *corrected* your point, which was incorrect.
One cannot indiscriminately increment or decrement a pointer
and expect nothing to go wrong. One must follow the rules.