Const sucks
Walter Bright
newshound1 at digitalmars.com
Mon Sep 10 15:11:04 PDT 2007
Janice Caron wrote:
>> const int* p = &x; // neither p nor *p can be changed
>> const(int*) p = &x; // neither p nor *p can be changed
>
> Two ways of writing the same thing. I don't understand the need for
> the bracketless version. Could we not just insist that the brackets
> must always be there? Or does the lack of brackets actually mean
> something? (if it does, it's back to being confusing again).
The bracketless version is for two reasons:
1) it's what people expect to have to type, for example:
void foo(const T t) { }
It will be the most common case.
2) it enables things like:
const
{
int a = 3;
int b = 4;
}
which is nice for a grouped collection of them.
More information about the Digitalmars-d
mailing list