D Bindings for C Opaque Pointers
Paul Backus
snarwin at gmail.com
Thu Dec 3 00:58:20 UTC 2020
On Thursday, 3 December 2020 at 00:30:06 UTC, Kyle Ingraham wrote:
>
> // EDSDKTypes.h
> typedef struct __EdsObject* EdsBaseRef;
> typedef EdsBaseRef EdsCameraListRef;
> //
>
[...]
>
> // edsdk.d
> struct EdsBaseRef;
> alias EdsBaseRef EdsCameraListRef;
You've dropped a level of indirection here. In the C header,
EdsBaseRef is a pointer, but in your D code, it is an opaque
struct.
The correct way to translate these C declarations into D is:
struct __EdsObject;
alias EdsBaseRef = __EdsObject*;
alias EdsCameraListRef = EdsBaseRef;
Note that unlike C, D does not allow us to refer to an incomplete
type without first declaring it.
More information about the Digitalmars-d-learn
mailing list