Passing an in parameter and aliasing

renoX renosky at free.fr
Wed May 23 13:38:08 PDT 2007


I'm not sure whether to post this in D.learn or not, but here's my issue:

What happens when you have a function f(in T array[], inout T x)
and that x is in fact an element of the array?

AFAIK, there are three possibilities:
1- the compiler detect the incompatibility and complain, that's nice for 
the programmer but real hard work for the compiler and it's impossible 
to catch all the problems for the compiler.

2- the array is modified when x is modified, which can leads to bug 
depending on the compiler and its optimization level: hopefully this 
would be a rare bug, but very hard to catch.
And if parameter passing is by default as constants, then maybe the bug 
won't be so rare.

3- the array is copied which reduce performance is this is done by default.

So which way is-it supposed to be?

Regards,
renoX



More information about the Digitalmars-d mailing list