errors when passing pointers from a unit_(re)

Sat, 26 Apr 1997 15:56:49 +0200 (MET DST)


According to skye:
> 
> var
> 	gBuffer"^mode13VideoBuffer;

You mean:  gBuffer: ^mode13VideoBuffer;-).

> [...]
> All my graphic functions draw to this buffer. To get it to the screen I
> have a procedre that calls an external C function:
> procedure gUpdate;
> begin
> 	screenblit( gBuffer);
> end;

How is this C function declared in the Pascal program?
As "Procedure ScreenBlit ( gBuffer: Pointer ); C;"?
Then it should work.

> [...]
> This only crashes when I pass it a pointer from my unit. I can do the exact
> same allocation from the main program file and it will work OK. 

This I don't understand.  You mean that you are using a statically
allocated video buffer in the Pascal program and passing a pointer to
it to the C program?  The following should work:

     Program Whatever;

     Type
       mode13VideoBuffer = array [ 1 .. 320 * 200 ] of Byte;
       mode13VideoBufferPtr = ^mode13VideoBuffer;

     Var
       gBuffer: mode13VideoBuffer;   (* NOT a pointer to it *)

     Procedure ScreenBlit ( Buffer: mode13VideoBufferPtr ); C;

     begin
       ScreenBlit ( @gBuffer );
     end.

> Am I getting confused on how pointers work in C and how they work in Pascal
> (I thought that they were pretty much the same except for type checking

Yes, they are.

> and "true" dynamic allocation)?

What's that?  What's "false" with `New' and `GetMem'?  :-)


Hope this helps,

    Peter

  Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer
peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201]
 maintainer GNU Pascal [970420] - http://home.pages.de/~gnu-pascal/ [970125]


Peter Gerwinski (peter@agnes.dida.physik.uni-essen.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es