several questions

Sergey Gromov snake.scaly at gmail.com
Sat Feb 16 18:57:47 PST 2008


Saaa <empty at needmail.com> wrote:
> How about passing a huge structure. Does this need something like a pointer 
> to the struct?
> I mean, is the passing done optimal here:
> 
> struct S{
> int n1=1;
> int n2=2;
> ..
> int n999=999;
> }
> 
> void func(S s){
> ..
> }
> 
> void main (){
> S t;
> func(t);
> ..
> } 

Use ref or pointer, whatever suits you best.  Usually ref is preferable 
because it makes no difference at the call site:

void func(ref S s){
..
}

void main (){
S t;
func(t);  // only a pointer is actually passed
..
}

If you use a pointer though, you must explicitly pass an address of your 
struct:

void func(S* s){
..
}

void main (){
S t;
func(&t); // explicit address expression
..
}

-- 
SnakE


More information about the Digitalmars-d-learn mailing list