Qs about structs and their references WRT C functions and variables
torhu
fake at address.dude
Wed Jan 31 09:46:50 PST 2007
Rick Mann wrote:
> c) I need to declare a couple of extern structs. Can I just slap an "extern (C)" on these and all will be well? The spec seems to indicate that this is so, and it may be fine; I'm just looking for verification. e.g.:
>
> struct
> ControlID
> {
> uint signature;
> int id;
> };
> typedef ControlID HIViewID;
> extern (C)
> const HIViewID kHIViewWindowContentID;
Try this:
extern extern (C) const HIViewID kHIViewWindowContentID;
http://www.digitalmars.com/d/declaration.html#extern
You need to add 'extern', just like in C headers. Then
kHIViewWindowContentID will be a pure declaration, and the linker will
look elsewhere for a definition. 'extern (C)' by itself only causes the
compiler to output the symbol with C instead of D name mangling.
If you link dynamically with the C lib, you are supposed to to add
'export' too, even if it works without that in some cases.
More information about the Digitalmars-d-learn
mailing list