`in` parameters made useful

IGotD- nise at nise.com
Sat Aug 22 08:24:06 UTC 2020


On Friday, 21 August 2020 at 23:16:53 UTC, tsbockman wrote:
>
> The risk of aliasing-related bugs comes from the availability 
> of pointers/references though, which will still be present in D 
> with or without this optimization. People who want to rule out 
> aliasing problems can just explicitly specify pass-by-value 
> using `scope const` instead of `in`.
>
> Let's not cripple the future of the language out of fear of 
> pitfalls that are already present, and cannot be entirely 
> removed as long as D remains a systems programming language.

Most of the parameters can actually be 'const', which also the 
case for 'in' parameters with the current definition. With const 
parameters, aliasing is no problem unless you do something with 
pointers further into the parameters.

'in' should be const by default like it is today and if not use 
inout or ref. With a language like D it is up to the programmer 
ensure there is no aliasing, much like the 'restrict' qualifier 
in C. I'm for that the compiler should detect any aliasing but 
this can be gradually improved.

The new 'in' qualifier is interesting enough not to through it 
away because of the aliasing problems.


More information about the Digitalmars-d mailing list