several questions

Saaa empty at needmail.com
Sun Feb 17 06:52:12 PST 2008


But if I use a ref or a pointer, the function is allowed to change the 
variable.
Using 'in' will make a copy?
I thought ref was just a renaming of  'inout'.
But there is no way to only pass a reference without giving the function 
write permission?

I sent a lot of big arrays in structs, so I think this is kind of crucial 
for me :/

> 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