Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!mtxinu!mtxinu.COM!ed From: ed@mtxinu.COM (Ed Gould) Newsgroups: comp.std.c Subject: Out-of-bounds pointers Message-ID: <1009@mtxinu.UUCP> Date: 3 Oct 89 01:01:38 GMT Sender: ed@mtxinu.COM Reply-To: ed@mtxinu.COM (Ed Gould) Organization: mt Xinu, Berkeley Lines: 21 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? void f() { char bug[100]; char *p; p = buf; p--; /* p contains an illegal value: &buf[-1] */ p++; /* hopefully, now p == &buf[0] */ if(p == buf) printf("It worked\n"); else printf("It failed\n"); }