Re: far pointer
- From: gordonb.yu9tt@xxxxxxxxxxx (Gordon Burditt)
- Date: Sun, 31 Jul 2005 08:01:47 -0000
>> >> > In C we can compare two pointers for equality,
>> >> > and if they point to the same address they will compare as equal.
>> >> > However there is another restriction,
>> >> > which is that pointers must be
>> >> > calculated within the object
>> >> > (array, to all intents and purposes) to which
>> >> > they point.
>> >> > If you play silly games with absolute addresses or wild
>> >> > calculations, you can defeat C's pointer representation,
>> >> > and it is posible
>> >> > that two pointers may point to the same location,
>> >> > but have different bit
>> >> > representations, and not compare as equal.
>
>If two pointers point to the same location,
>they will compare equal regardless of whether or not
>the bit patterns are the same.
If two pointers *that you could create without invoking undefined
behavior* point to the same location, they will compare equal
regardless of whether or not the bit patterns are the same.
That means that if you are working with a x86 machine in real mode,
with 16-bit segment and 16-bit offset, and you're allowing objects
larger than 64k, that you (the implementor) have to do somewhat
complicated and slow code to do pointer math, and you probably have
to normalize two pointers as part of comparing them for equality.
If, on the other hand, you do NOT allow objects larger than 65535
bytes, the implementation can just do simple pointer math (involving
only the offset), and as long as the implementation doesn't allow
a legitimate way to GET pointers to the same object with different
segment register contents, and comparison can just do a bit-by-bit
comparison (although for equality it still has to compare 32 bits.
>> If you want to compare two pointer values using "<", "<=", ">", or
>> ">=", both pointers must point into the same object (or just past the
>> end of it). If you want to compare two pointer values using "=" or
>> "!=", they just both have to be valid, i.e., each has to point into
>> *some* object, not necessarily the same one (or just past the end of
>> some object, and there's a special case allowing two objects to be
>> adjacent).
Gordon L. Burditt
.
- Follow-Ups:
- Re: far pointer
- From: pete
- Re: far pointer
- References:
- far pointer
- From: Meenu
- Re: far pointer
- From: pete
- Re: far pointer
- From: Keith Thompson
- Re: far pointer
- From: pete
- far pointer
- Prev by Date: Re: memcpy broken?
- Next by Date: Re: memcpy broken?
- Previous by thread: Re: far pointer
- Next by thread: Re: far pointer
- Index(es):
Relevant Pages
|