Use C struct declaration without knowing definition

Ben Ogles benjaminogles at gmail.com
Thu Jul 25 00:35:35 UTC 2019


Is there a way to use a C header that contains a struct 
declaration but no definition?

For example, the C header may contain:

typedef struct some_type_s some_type;

Which is only fully defined in the implementing C file:

struct some_type_s { ... };

I am trying to wrap the header in D:

extern(C)
{
   struct some_type_s;
   alias some_type = some_type_s;
}

And then use it in another D file:

some_type s;

But dmd does not know the size of the struct so it can't compile. 
Is there a work around to this other than moving the struct 
definition into the C header file?



More information about the Digitalmars-d-learn mailing list