in vs. const

Sergey Gromov snake.scaly at gmail.com
Sat Mar 7 17:39:19 PST 2009


Sat, 7 Mar 2009 15:37:07 +0000 (UTC), 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)
> 
> ?

In D1, there are no const types, so the first form doesn't compile.  In
the second form 'in' is redundant,  it means the default behavior and
may be omitted without consequences.

In D2, 'in' means 'const scope'.  I've seen that in writing but can't
remember where.

Therefore clever people use 'in' to mean 'const' in D2 and NOP in D1 to
improve portability.



More information about the Digitalmars-d mailing list