Declaring Far pointers in Pascal, i.e. pointers that point to mem outside of stack! 
Author Message
 Declaring Far pointers in Pascal, i.e. pointers that point to mem outside of stack!

I've got a lot of code that works in c for displaying sprites and pcx
images, but it uses far pointers. Does anyone know how to declare far
pointers in Pascal ?????

thanks in advance




Wed, 18 Jun 1902 08:00:00 GMT  
 Declaring Far pointers in Pascal, i.e. pointers that point to mem outside of stack!


: I've got a lot of code that works in c for displaying sprites and pcx
: images, but it uses far pointers. Does anyone know how to declare far
: pointers in pascal ?????

I believe that all pointers in Turbo Pascal are 'far' (that is they
can reference anywhere within the first meg of memory)  I don't know
what you mean 'pointers that point to mem outside of stack' as most
pointers do that anyway - I think you mean outside of the heap, which

unary & operator)

Steve
--
 ____ ____

\__ \ |  _/-----------------------------------------------------
/___/ |_|    (yes, I know it's a BUAF, but it's *my* BUAF) :-)



Wed, 18 Jun 1902 08:00:00 GMT  
 Declaring Far pointers in Pascal, i.e. pointers that point to mem outside of stack!


Quote:
>I've got a lot of code that works in c for displaying sprites and pcx
>images, but it uses far pointers. Does anyone know how to declare far
>pointers in pascal ?????
>thanks in advance


Depends on the version, of course.  Assuming tp 4.0 or greater, the {$F}
compiler directive does is.  Declaring pointers in the interface section also
makes them far automatically.
Hope this helps,
Jochen


Wed, 18 Jun 1902 08:00:00 GMT  
 Declaring Far pointers in Pascal, i.e. pointers that point to mem outside of stack!

Quote:

> I've got a lot of code that works in c for displaying sprites and pcx
> images, but it uses far pointers. Does anyone know how to declare far
> pointers in pascal ?????

> thanks in advance



your question actually came in an assembly book for hte IBM PC..go
figure.  Pascal automaticaly chooses which version of the pointer to
use, whereas in C, depending on your memory model, declaring which
version of the pointer to use is very important.  You can force far
calls in pascal by using the {F+} compiler directive, then using the
{F-} compiler directive to allow pascal to choose.  

        Here's an example I'm sure you're familiar with :

c implementation :
        unsigned char far *video_buffer = (char far *)0xA0000000L;

pascal implementation :
        video_buffer : ^byte = ptr($A000, $0);

- mercutio



Wed, 18 Jun 1902 08:00:00 GMT  
 Declaring Far pointers in Pascal, i.e. pointers that point to mem outside of stack!

Quote:


>>I've got a lot of code that works in c for displaying sprites and pcx
>>images, but it uses far pointers. Does anyone know how to declare far
>>pointers in pascal ?????
>>thanks in advance

>Depends on the version, of course.  Assuming tp 4.0 or greater, the {$F}
>compiler directive does is.  Declaring pointers in the interface section also
>makes them far automatically.

No, all *pointers* are far.  {$F+}/{$F-} has absolutely no relevance to
pointers -- it has to do with the calling and return conventions used in
procedures and functions.  Near functions can only be called from the same
unit and exit with retn (pop IP from stack).  Far functions can be called
from the same unit (or others if declared in the interface) and exit with
retf (pop CS:IP from stack).

Quote:
>Hope this helps,
>Jochen

--
Scott Earnest          | We now return you to our regularly scheduled |



Wed, 18 Jun 1902 08:00:00 GMT  
 Declaring Far pointers in Pascal, i.e. pointers that point to mem outside of stack!

Quote:


>> I've got a lot of code that works in c for displaying sprites and pcx
>> images, but it uses far pointers. Does anyone know how to declare far
>> pointers in pascal ?????

>> thanks in advance


>your question actually came in an assembly book for hte IBM PC..go
>figure.  Pascal automaticaly chooses which version of the pointer to
>use, whereas in C, depending on your memory model, declaring which
>version of the pointer to use is very important.  You can force far
>calls in pascal by using the {F+} compiler directive, then using the
>{F-} compiler directive to allow pascal to choose.  

note that if you're doing procedural variables (i.e. jump-tables,
dynamic function calls, etc.) it's a good idea to use far calls all
the time.

either that or use TMT Pascal which is in pmode (i.e. no such THING as
a far pointer :)

---
      quantum porcupine, coder, musician        |   that which is, is not

http://infinity.beve.blacksburg.va.us/~porcpine | that which does, does not



Wed, 18 Jun 1902 08:00:00 GMT  
 Declaring Far pointers in Pascal, i.e. pointers that point to mem outside of stack!


Quote:


>>> I've got a lot of code that works in c for displaying sprites and pcx
>>> images, but it uses far pointers. Does anyone know how to declare far
>>> pointers in pascal ?????
>> Pascal automaticaly chooses which version of the pointer to
>>use
>>You can force far
>>calls in pascal by using the {F+} compiler directive, then using the
>>{F-} compiler directive to allow pascal to choose.  

Not quite correct. mercuito asks AFAIS for pointer to images (=raw
data) and not to procedures (or functions).
The explaination of {$F+} is correct, but {$F+} do not affect pointer
to memory locations (as in  TYPE  TP_WORD = ^ WORD ).
They are *always* (in BP7 for DOS AND DPMI)  FAR POINTERS, there are
no other types. And they can point everywhere ( p := Ptr($A000,0123)
).
sizeof(TP_WORD) is always 4 an you can cast them from/to Longint.
And do things like:

TYPE TX = LONGINT {Try byte,word ...};
VAR p : ^TX;
    w : ARRAY[0..30] OF TX;
    i : Integer;
BEGIN
  FOR i := 0 TO 30 DO w[i] := 3*i;

  Writeln(p^); { = 0 }
  Inc(p,20);
  WriteLn(p^); { = 60 }
END.

(same as in C :-)

Walter



Wed, 18 Jun 1902 08:00:00 GMT  
 Declaring Far pointers in Pascal, i.e. pointers that point to mem outside of stack!

Reposting article removed by rogue canceller.


Quote:


>>> I've got a lot of code that works in c for displaying sprites and pcx
>>> images, but it uses far pointers. Does anyone know how to declare far
>>> pointers in pascal ?????
>> Pascal automaticaly chooses which version of the pointer to
>>use
>>You can force far
>>calls in pascal by using the {F+} compiler directive, then using the
>>{F-} compiler directive to allow pascal to choose.  

Not quite correct. mercuito asks AFAIS for pointer to images (=raw
data) and not to procedures (or functions).
The explaination of {$F+} is correct, but {$F+} do not affect pointer
to memory locations (as in  TYPE  TP_WORD = ^ WORD ).
They are *always* (in BP7 for DOS AND DPMI)  FAR POINTERS, there are
no other types. And they can point everywhere ( p := Ptr($A000,0123)
).
sizeof(TP_WORD) is always 4 an you can cast them from/to Longint.
And do things like:

TYPE TX = LONGINT {Try byte,word ...};
VAR p : ^TX;
    w : ARRAY[0..30] OF TX;
    i : Integer;
BEGIN
  FOR i := 0 TO 30 DO w[i] := 3*i;

  Writeln(p^); { = 0 }
  Inc(p,20);
  WriteLn(p^); { = 60 }
END.

(same as in C :-)

Walter



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. pointers, pointers, pointers...

2. Pointers Pointers Pointers

3. Point a pointer to a *specific* memory location?

4. A Pointer That Won't Point!!!

5. Pointers to pointers

6. Beginner needs some pointers with pointers!

7. POINTERS POINTERS...

8. Turbo Pascal Frequently Asked Questions, a monthly pointer

9. Turbo Pascal Frequently Asked Questions, a monthly pointer

10. Turbo Pascal Frequently Asked Questions, a monthly pointer

11. Turbo Pascal Frequently Asked Questions, a monthly pointer

12. Turbo Pascal Frequently Asked Questions, a monthly pointer

 

 
Powered by phpBB® Forum Software