...ing logging 4.0

はてなブログに移行しました。D言語の話とかいろいろ。

in vs. const

Sean Kelly wrote:

> > dsimcha wrote:
>> >> All the discussion about const on this NG lately has made me realize that
>> >> I have no idea what the difference is between const and in, i.e. what is
>> >> the difference between:
>> >>
>> >> SomeType foo(const SomeType bar) and
>> >> SomeType foo(in SomeType bar)
> >
> > There's no difference between them. The 'in' version just happens to be
> > D1-compatible, and its meaning could be more easily changed over time if
> > any tweaking is necessary (unlikely).
I have not done any D2, but surely 'in' is modifiable in the function locally
where as const is not (so since const is not modifiable at all it implies
in).
For example:

void myfunc(in int i)
{
i = 10; // i is changed to 10, k stays as 12
}

int k = 12;
myfunc(k);

=================================

void myfunc(const int i)
{
i = 10; // Fails to compile as i is const
}

in k = 12;
myfunc(k);

・・・あれ? inってこうなるんだっけ.