Re: function ref param vs pointer param

2015-04-24 Thread bearophile via Digitalmars-d-learn
On Friday, 24 April 2015 at 13:39:35 UTC, ref2401 wrote: processPointer(ms); I think doing this way is more descriptive. Now all readers know that ms might be changed inside the function. C# avoids that problem requiring (in most cases) the usage of ref at the calling point too. But this

Re: function ref param vs pointer param

2015-04-24 Thread Ali Çehreli via Digitalmars-d-learn
On 04/24/2015 06:23 AM, ref2401 wrote: What advantages do ref params give over pointer params? Another difference is that a ref parameter is not null and what is referred to is not an rvalue. However, it is possible to break that expectation if a pointer is dereferenced and passed to a

Re: function ref param vs pointer param

2015-04-24 Thread ref2401 via Digitalmars-d-learn
Thank you

Re: function ref param vs pointer param

2015-04-24 Thread bearophile via Digitalmars-d-learn
ref2401: void processRef(ref MyStruct ms) { writeln(processRef: , ms); } void processPointer(MyStruct* ms) { writeln(processPointer: , *ms); ref params don't need the * every time you use them inside the function, and don't need the when you call the function. Bye,

Re: function ref param vs pointer param

2015-04-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/24/15 9:23 AM, ref2401 wrote: What advantages do ref params give over pointer params? struct MyStruct { string str; this(string str) { this.str = str; } } void processRef(ref MyStruct ms) { writeln(processRef: , ms); } void processPointer(MyStruct* ms) {

Re: function ref param vs pointer param

2015-04-24 Thread ref2401 via Digitalmars-d-learn
processPointer(ms); I think doing this way is more descriptive. Now all readers know that ms might be changed inside the function.