[fpc-devel] i8086 huge pointers

Nikolay Nikolov nickysn at gmail.com
Mon Apr 7 00:02:37 CEST 2014


I started investigating huge pointer support in 16-bit C compilers and 
discovered there are at least two different implementations:


Borland C++ 3.1:

Huge pointers aren't changed when converting from a far pointer. They 
are normalized as soon as some pointer arithmetic is performed on them. 
Normalization means changing the segment and the offset in such a way 
that it still points to the same linear address ( =segment*16+offset ), 
but the offset is always between $0000 and $000F. So:

HugePointer(Ptr($1234,$5678)) = $1234:$5678
HugePointer(Ptr($1234,$5678))+1 = $179B:$0009
HugePointer(Ptr($1234,$5678))-1 = $179B:$0007


Microsoft C/C++ 7.0 and Open Watcom 1.9:

Huge pointers aren't changed when converting from a far pointer (same as 
Borland). However, during pointer arithmetic, they aren't normalized 
like in Borland, but the segment is changed only when the offset 
overflows, i.e.:

HugePointer(Ptr($1234,$5678)) = $1234:$5678
HugePointer(Ptr($1234,$5678))+1 = $1234:$5679
HugePointer(Ptr($1234,$5678))-1 = $1234:$5677
HugePointer(Ptr($1234,$FFFF))+1 = $2234:$0000
HugePointer(Ptr($1234,$0000))-1 = $0234:$FFFF


Back in the old days, I never used huge pointers, because I wrote in 
Turbo Pascal, which didn't have them, so I don't have an opinion which 
way is better. So, which way should FPC for i8086 follow?

Nikolay



More information about the fpc-devel mailing list