Array as an argument, ambiguous behaviour.

Cooler kulkin at hotbox.ru
Wed Jan 29 06:34:53 PST 2014


On Wednesday, 29 January 2014 at 13:38:22 UTC, simendsjo wrote:
> On Wednesday, 29 January 2014 at 13:15:30 UTC, Cooler wrote:
>> On Wednesday, 29 January 2014 at 12:40:00 UTC, Tobias Pankrath 
>> wrote:
>>> On Wednesday, 29 January 2014 at 11:46:23 UTC, Cooler wrote:
>>>> Thank you for detailed explanation. But the question is - 
>>>> "Is that correct that language allows ambiguous behavior?"
>>>
>>> Where is it ambiguous?
>>
>> Ambiguity is here...
>> When I call fun1() or fun2() I know the behavior directly from 
>> function signature (read the comments in my first post). For 
>> fun3() case the caller side don't know the behavior directly 
>> from function signature. To know what will happen with array 
>> "a", the caller must see to fun3() body.
>> Ambiguity is - in first and second cases the caller knows what 
>> happens with "a", but in third case the caller does not know 
>> what happens with "a".
>
> 'in' is a shorthard for 'const scope'.
> 'const' means that the callee cannot change the passed in 
> parameter in any way, including anything available through that 
> type (for example x[0])
> 'scope' means it cannot leave the scope of the callee - that it 
> cannot be stored away anywhere.
> 'ref' means that the parameter is passed by reference, and thus 
> might be reassigned or changed in any way.
>
> No parameters means that it's mutable, but the reference cannot 
> change.
>
> I don't see any ambiguities here.

Don't anybody understand me?!

I know what means "in" and "ref" qualifiers!

> No parameters means that it's mutable, but the reference cannot 
> change.
Here is ambiguity.
void fun3(int[] x){ x ~= 5; ... }
auto a = new int[10];
fun3(a); // Here content of "a" may be changed or may be not 
changed. Depends on the buffer size that system will allocate for 
"a" array.


More information about the Digitalmars-d-learn mailing list