Recent

Author Topic: x64 vs x86 storing function pointers  (Read 971 times)

daobh

  • Newbie
  • Posts: 3
x64 vs x86 storing function pointers
« on: April 18, 2021, 09:34:13 pm »
Sorry if this is obvious, I've been searching and fiddling and I can't seem to figure it out...

In delphi 5, I can do something like this

Code: Pascal  [Select][+][-]
  1. var
  2.   someprocedure: procedure;
  3.   somefunction: function(a: integer): boolean;
  4.  
  5. procedure LoadAPI(var T);
  6. var
  7.   Table : array [0..1] of Pointer absolute T;
  8. begin
  9.   someprocedure := Table[0];
  10.   somefunction := Table[1];
  11. end;

But FP balks at the assignments (someprocedure := Table[0])  Is there a simple way to massage this to work or just the verbose route of...
Code: Pascal  [Select][+][-]
  1. type
  2.   someprocedureType = procedure;
  3.   somefunctionType = function(a: integer): boolean;
  4. var
  5.   someprocedure: someprocedureType;
  6.   somefunction: somefunctionType;
  7.  
  8. procedure LoadAPI(var T);
  9. var
  10.   Table : array [0..1] of Pointer absolute T;
  11. begin
  12.   someprocedure := someprocedureType(Table[0]);
  13.   somefunction := somefunctionType(Table[1]);
  14. end;


Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: x64 vs x86 storing function pointers
« Reply #1 on: April 18, 2021, 09:37:27 pm »
If you use {$mode delphi}, it should compile in FPC as well. In FPC syntax modes, plain pointers are indeed not type-compatible with procedural variables for increased type safety.

daobh

  • Newbie
  • Posts: 3
Re: x64 vs x86 storing function pointers
« Reply #2 on: April 18, 2021, 11:16:50 pm »
I'll work on that direction a bit, I tried delphi but was using ObjFPC instead since it ended up getting a little further.  Will back track and play around though!  Thanks!

daobh

  • Newbie
  • Posts: 3
Re: x64 vs x86 storing function pointers
« Reply #3 on: April 19, 2021, 04:56:08 am »
Using -Mdelphi worked after I cleaned up a couple of other minor issues.

- functions declaring var result.  commented out.
- some usage of byte(hi(XX)) changed to byte(hi(word(XX))), untested but compiling

Thanks again!

 

TinyPortal © 2005-2018