Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!unmvax!bbx!bbxsda!scott From: scott@bbxsda.UUCP (Scott Amspoker) Newsgroups: comp.std.c Subject: Re: Out-of-bounds pointers Message-ID: <202@bbxsda.UUCP> Date: 5 Oct 89 17:20:24 GMT References: <1009@mtxinu.UUCP> <4199@letni.UUCP> Reply-To: scott@bbxsda.UUCP (Scott Amspoker) Organization: Basis International, Albuquerque, NM Lines: 27 In article <4199@letni.UUCP> doug@letni.LawNet.Com (Doug Davis) writes: >In article <1009@mtxinu.UUCP> ed@mtxinu.COM (Ed Gould) writes: >> void >> f() { >> char bug[100]; > ^^^^^^^^^^ I assume you mean buf here, right? >> char *p; >> >> p = buf; >> >> p--; /* p contains an illegal value: &buf[-1] */ > ^^^ Opps, You have now entered the land of illegal addresses, > normally called the twilight zone, incrementing the > pointer is no longer guarenteed to be == &buf[0], that > is installation dependent. Most likely it will == something > really weird and you get a core dump. Which one you get > is left as an exercise to the reader. Agreed, it is undefined. However *most likely* it will work just fine (based on the several dozen systems I've worked with). I would recommend avoiding it though. -- Scott Amspoker Basis International, Albuquerque, NM (505) 345-5232