Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!sdrc!scjones From: scjones@sdrc.UUCP (Larry Jones) Newsgroups: comp.std.c Subject: Re: Out-of-bounds pointers Message-ID: <844@sdrc.UUCP> Date: 3 Oct 89 22:01:24 GMT References: <1009@mtxinu.UUCP> Organization: Structural Dynamics Research Corp., Cincinnati Lines: 21 In article <1009@mtxinu.UUCP>, ed@mtxinu.COM (Ed Gould) writes: > Is the following code conformant? It's clear that it's not legal to > dereference the pointer in its "illegal" state, but is the p++ line > guaranteed to return it to a valid value? What would it (be expected > to) print? > > p = buf; > p--; /* p contains an illegal value: &buf[-1] */ > p++; /* hopefully, now p == &buf[0] */ Nope. Once you've decremented p you've entered the twilight zone of undefined behaviour where your program could dump core, play the Star Spangled Banner, or continue on. If it continued, the increment may or may not set it pointing to buf again. ---- Larry Jones UUCP: uunet!sdrc!scjones SDRC scjones@SDRC.UU.NET 2000 Eastman Dr. BIX: ltl Milford, OH 45150-2789 AT&T: (513) 576-2070 "I have plenty of good sense. I just choose to ignore it." -Calvin