Farpointers Was: Re: RE: [fpc-pascal]Problem with CASE statement
Thomas Schatzl
tom_at_work at gmx.at
Wed Mar 24 10:58:43 CET 2004
Hello,
> Second - new FPC v1.9.x for statement
>
> var p:pointer
> p:=Ptr(a,b);
>
> shows error "Incompatible types: got "FarPointer" expected "Pointer"".
>
> I found i can declare var p:farpointer;
> but i did not found any description for this type of pointer
> how can i use it.
It seems that the syntax and semantics of this function changed with later
FPC-versions to something actually useful... ;-)
A "Farpointer" is a pointer consisting of a 16 bit selector and 32 bit
offset, while in BP the Ptr() function expected a 16bit/16bit
segment:offset.
This is due to different memory models in 32 bit protected mode of FPC and
16 bit real mode in BP/TP. There is no fully compatible automatic way to
handle these problems.
In short, you usually don't ever need the Ptr() - function in FPC because
all memory is addressed linearly through a single 32 bit address, just use
"p := @avariable" if you want to create a pointer to some memory area.
It was sometimes required in BP/TP because of memory segmentation in BP
programs.
Otoh if you want to access specific memory areas in the real mode memory
area (lower 1MB of memory) you need to do some sort of translation.
See the go32 - documentation for further details (there is some information
about the farpointer stuff as well iirc) if you just want to port your TP/BP
DOS application to the go32v2 target.
For the others such a way of accessing memory will not be allowed by the OS
anyway (or is limited) and is impossible to do without lots of application
and OS specific code.
Eventually this will give you a farpointer to the DOS memory location you
want to access:
uses go32;
var p : farpointer;
// this syntax is just a guess.
p := Ptr(getfs(), a shl 4 + b);
getfs() returns a selector which by default describes the DOS memory
area. Note that while constructing a pointer to this area might work in all
cases, any NT-based OS might prevent access. At least it will be slow. Don't
even consider using this on e.g. *nix systems.
Regards,
Thomas
More information about the fpc-pascal
mailing list