Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!oberon!nunki.usc.edu!jeenglis From: jeenglis@nunki.usc.edu (Joe English) Newsgroups: comp.lang.c Subject: Re: detecting invalid pointers Message-ID: <3092@nunki.usc.edu> Date: 17 Mar 89 05:21:23 GMT References: <15495@cup.portal.com> <11998@haddock.ima.isc.com> <3011@nunki.usc.edu> <12043@haddock.ima.isc.com> Reply-To: jeenglis@nunki.usc.edu (Joe English) Distribution: usa Organization: University of Southern California, Los Angeles, CA Lines: 33 karl@haddock.ima.isc.com (Karl Heuer) writes: >In article <3011@nunki.usc.edu> jeenglis@nunki.usc.edu (Joe English) writes: >>karl@haddock.ima.isc.com (Karl Heuer) writes: >>>This works because pointer *equality* is well-defined even on pointers into >>>different arrays. >> >>Well, maybe not... [80x86 in large model with unnormalized pointers] > >If the compiler ever generates unnormalized pointers, then it had better be >prepared to generate code to compare them correctly. You're right, but Turbo C (and probably MSC as well) don't bother to most of the time. Since in 'large' model all arrays have to fit in the same segment, any two pointers calculated from the base of the array can be compared just by their offsets. In normal usage, this isn't a problem; however, it is possible for two pointers into *different* arrays to test equal -- which isn't that bad, since that's a meaningless comparison to start with -- or for a normalized (cast to huge *) pointer to test unequal to the equivalent non-normalized value -- which can cause problems and is one of the many reasons why I don't use 'large' model. (According to the TC documentation, pointers cast to huge or in the huge model always compare correctly, but the execution speed suffers terribly.) --Joe English jeenglis@nunki.usc.edu