On 2010-11-26 07:51:20 -0500, Jens Mueller <jens.k.muel...@gmx.de> said:

Trass3r wrote:
In TDPL const/immutable are type qualifiers. Type qualifier is a
synonym for type modifier, isn't it? And I know storage classes like
static/ref. In C you have the type qualifiers const, volatile, and
restrict and the storage classes auto, register, static, extern. Now
const in D is a storage class?

I also think const char* x in D2 is equal to const(char*) x while a
direct translation would be const(char)* x
So you might use the former version to keep compatibility with D1.

Haven't thought about that.
Right. In D2 const T* is equal to const(T*).

Let's check all the possible cases:
void foo(const int *non_const_ptr_to_const,
         char *const const_ptr_to_non_const,
         const float *const const_ptr_to_const);

In D2 you cannot express char *const. That's due to the transitivity of
const. You can only do a const char* which is a constant pointer to
constant.
That's why I think foo should become in D2
void foo(const int*, char *, const(float*));

What do you think?

const(float*) or const(float)* are pretty much equivalent as a function parameter type. That's because the pointer is being passed to the function by copy. So whether it is const or not only matter when you are writing the function's body (can't mutate the local variable). It doesn't change anything for the caller.


--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/

Reply via email to