Extended Type Design.

Derek Parnell derek at psych.ward
Fri Mar 16 12:50:23 PDT 2007


On Fri, 16 Mar 2007 11:02:39 -0700, Andrei Alexandrescu (See Website For
Email) wrote:


> void print(const char[] message); // not modifying message
> 
> void main()
> {
>    char[] myMessage = readln();
>    print(myMessage); // error! myMessage is changeable!
> }
> 
> I truly think we've distilled the simplest language within our requirements.

Maybe the concepts but I'm not so sure about the usage.

Given a function signature that has an array argument, there are two
independant things we might want to remain unchangeable - the reference and
the data referred to. 

To me, the signature ...

  void print(const char[] message)

looks like 'const' is qualifying 'char[]' because that's what it is next
to, and the 'message' looks like it is not qualified. So the signature
looks like it is saying, the data is 'const' but the reference is not.

Thus this below signature looks more like what you are trying to express
...

  void print(char[] const message)

And to make both unchangeable then this looks better to me ...

  void print(const char[] const message)

-- 
Derek Parnell
Melbourne, Australia
"Justice for David Hicks!"
skype: derek.j.parnell



More information about the Digitalmars-d mailing list