From Ada 2012

Alex Rønne Petersen xtzgzorex at gmail.com
Thu May 3 11:51:46 PDT 2012


On 03-05-2012 20:29, Alex Rønne Petersen wrote:
> On 03-05-2012 19:36, Steven Schveighoffer wrote:
>> On Thu, 03 May 2012 13:03:34 -0400, Kagamin <spam at here.lot> wrote:
>>
>>> On Thursday, 3 May 2012 at 14:04:41 UTC, bearophile wrote:
>>>> [p.21]
>>>>> The compiler decides if it has to be passed by reference of copy
>>>>> procedure Do_Something
>>>>> (P1 : in Huge_Structure) –- Passed by reference if too big
>>>>
>>>> D offers more low-level knowlege/control here, it doesn't decide to
>>>> pass by value or reference, leaving the decision to the programmer, I
>>>> prefer D here.
>>>> But in D code like this, where a large value is passed, I'd like the
>>>> D compiler to give a warning (despite once in a while that's exactly
>>>> what you want?):
>>>>
>>>> alias int[1_000] TA;
>>>> void int(TA a) {}
>>>
>>> I was surprised a little when compiler rejected `ref in`.
>>
>> in is synonymous for "const scope".
>>
>> Doing "const scope ref" yields:
>>
>> "scope cannot be ref or out"
>>
>> which makes sense. Just use const instead.
>>
>> -Steve
>
> Doesn't make sense to me. It seems perfectly normal to do something like
> this:
>
> void foo(ref in int i)
> {
> i = 42; // we're setting i indirectly, and not leaking it
> }
>
> int i;
> foo(i);
>

On second thought, the 'const' in the 'in' would probably make this 
nonsensical. Still, passing structs by ref is a case where 'ref in' 
makes sense (e.g. matrices).

-- 
- Alex


More information about the Digitalmars-d mailing list