C函数指针转换成Delphi/Pascal?

Ram*_*ish 5 c delphi pascal pointers function-pointers

我目前正在将一些C头文件转换为Delphi.我找不到将函数指针从C转换为Delphi的引用.

typedef _JAlloc JAlloc;  
struct _JAlloc {  
    void *(*alloc) (JAlloc *allocator, size_t size);  
    void (*free) (JAlloc *allocator, void *p);  
    void *(*realloc) (JAlloc *allocator, void *p, size_t size);  
};
Run Code Online (Sandbox Code Playgroud)
  1. Delphi的翻译是什么?

  2. 在哪里可以找到将C头手动转换为Delphi的良好资源(包括指针,预处理器指令等)?

Arn*_*hez 9

使用这种代码

type
  PJAlloc = ^TJAlloc;
  TJAllocAlloc = function(allocator: PJAlloc; size: integer): pointer; cdecl;
  TJAllocFree = procedure(allocator: PJAlloc; p: pointer); cdecl;
  TJAllocRealloc = function(allocator: PJAlloc; p: pointer; size: integer); cdecl;
  TJAlloc = record
    alloc: ^TJAllocAlloc;
    free: ^TJAllocFree;
    realloc: ^TJAllocRealloc;
  end;
Run Code Online (Sandbox Code Playgroud)

并将cdecl更改为stdcall,具体取决于C库的调用约定.

一个替代声明(或许更多'pascalish')可能是:

type
  TJAllocAlloc = function(var allocator: TJAlloc; size: integer): pointer; cdecl;
  TJAllocFree = procedure(var allocator: TJAlloc; p: pointer); cdecl;
  TJAllocRealloc = function(var allocator: TJAlloc; p: pointer; size: integer); cdecl;
  TJAlloc = record
    alloc: ^TJAllocAlloc;
    free: ^TJAllocFree;
    realloc: ^TJAllocRealloc;
  end;
Run Code Online (Sandbox Code Playgroud)