Qs about structs and their references WRT C functions and variables

Rick Mann rmann-d-lang at latencyzero.com
Tue Jan 30 18:03:21 PST 2007


Jarrett Billingsley Wrote:

> Right.  'out' implicitly passes the struct by reference, so if the struct 
> parameter is a return value, then 'out' is the right way to go.  That it 
> works with C libraries is something that I didn't know, and something very 
> cool..

It makes for tidy calls where the parameter is used for output. However, I can't seem to do the same for an input parameter. I'd like to do the equivalent of the following C code:

void func(const SomeStruct& inS);

This is identical to

void func(const SomeStruct* inS);

but allows me to call it without adding the & in front of the parameter. It's a bit inconsistent that I can do this with an "out" parameter, but not an "in" parameter.


> Hmm.. if I remember correctly, those extern struct declarations have to be 
> in a .d file which is _imported_ but never _compiled_.  So you'd have 
> something like
> 
> importedstructs.d
> 
> struct ControlID
> {
>     uint signature;
>     int id;
> }
> 
> typedef ControlID HIViewID;
> extern(C) const HIViewID kHIViewWindowContentID;
> 
> And then the rest of your program would have:
> 
> import importedstructs;
> 
> But you wouldn't put importedstructs.d on the command line when you compile 
> your program. 

I finally got to try that code. Seems to work, even with compiling the class in which it's declared.

Thanks!


More information about the Digitalmars-d-learn mailing list