IDEA: Use Unix-style chmod values for const and invariant

Regan Heath regan at netmail.co.nz
Fri Nov 30 04:27:44 PST 2007


Janice Caron wrote:
> On Nov 30, 2007 9:16 AM, Regan Heath <regan at netmail.co.nz> wrote:
>>> Has anyone thought of using "in" for readonly view? Keywords don't
>>> come much shorter. Its existing use is about as useful as unary plus.
>> We already use it for function parameters...
>>
>> http://www.digitalmars.com/d/function.html
>> "The in storage class is equivalent to final const scope"
> 
> And yet, this compiles and runs in D2.0
> 
>     int f(in int x)
>     {
>         ++x;
>         return x;
>     }
> 
>     void main()
>     {
>         int n = 42;
>         int m = f(n);
>     }
> 
> It doesn't seem to mean const to me. (Anyway, "final" has been ditched).

So, the questions become:

1. does "in" still mean "const scope" (final being ditched)
2. if #1, does "const scope int x" mean that ++x should fail

To answer #1 someone would have to dig round in the DMD front end I 
suspect.  Or get an answer from Walter answer.  Or, code two functions 
one using "in" and the other "const scope" and see if the behaviour is 
identical.

To answer #2 ... Careful reading of Walters post about const, also what 
happens when you try the above with a class reference instead of an int?

I haven't taken the time to really get inside the new system yet, which 
is why I'm asking the questions instead of answering them.

Regan



More information about the Digitalmars-d mailing list