Qs about structs and their references WRT C functions and variables

Rick Mann rmann-d-lang at latencyzero.com
Tue Jan 30 17:15:42 PST 2007


I'm working on some C bindings, and I need to know a few things that aren't clear from the spec.

a) If a C function takes a pointer to a struct so that it can fill that struct (return it), I've found I can write the parameter as "out MyStruct outS", and things work as expected (I don't take the address of the parameter I pass).

If a function simply takes a struct as input, and therefore I leave off any qualifier in the D parameter declaration (i.e., "MyStruct inS"), is the struct still passed by reference? I assume so, but want to be sure.

b) Some of the API's in C pass the entire struct (I question the wisdom of this). How do I link to these?

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;

TIA,
Rick




More information about the Digitalmars-d-learn mailing list