Return by 'ref' problems...

Jakob Ovrum jakobovrum at gmail.com
Fri May 4 13:16:48 PDT 2012


On Friday, 4 May 2012 at 20:00:10 UTC, Jacob Carlborg wrote:
>
> ref int a ();
> const int b ();
> const(int) c ();

I fully understand the difference, it's a common source of 
confusion. But it also makes perfect sense if you know the rules 
about function attributes. I don't think it's optimal, but 
changing it now would break a lot of code, it cannot happen for 
D2. The best we can do is make 'ref' work properly as a function 
attribute by allowing it to occur after the parameter list.

'inout' also has this problem, but opposite; sometimes putting it 
in front of the member function makes it behave differently. I 
can't remember if there is a bug report for it (probably is... or 
maybe not, because nobody even expected inout to work at all a 
couple of versions ago).

> Perhaps it would be better if "a" was declared like this:
>
> ref(int) a ();

ref is not a type qualifier, I think that would be even more 
confusing. It would be completely out of sync with the rest of 
the language.



More information about the Digitalmars-d mailing list