[fpc-pascal] Forward struct declaration in C

Michael Van Canneyt michael at freepascal.org
Fri Feb 22 12:21:38 CET 2013



On Fri, 22 Feb 2013, dhkblaszyk at zeelandnet.nl wrote:

> Hi,
>
> I'm porting a piece of software to FPC but I got stuck at a forward struct
> declaration. The situation is as folows.
>
> Header 1 declares:
>    struct TaskHandle__;
>    typedef void (*CallBackProcPtr)(struct TaskHandle__ *task);
>
> And Header2 provdes:
>    typedef struct TaskHandle__ { int unused; } *TaskHandle
>
> However header 2 already references header 1 because it already contains
> some other type definitions, so I cannot reference header 2 in header 1
> because of a circular dependency. Can FPC do something similar to C and
> define a forward record?

No. What you can do is merge the headers in a single unit:
PTaskHandle__ = ^TTaskHandle__;
and define TTaskHandle__  in the same block

The CallBackProcPtr only needs a pointer, so you could also simply define a pointer.

Michael.



More information about the fpc-pascal mailing list