Const Ideas

Craig Black cblack at ara.com
Mon Dec 3 08:55:16 PST 2007


"Craig Black" <cblack at ara.com> wrote in message 
news:fj16ut$qgf$1 at digitalmars.com...
>
> "Janice Caron" <caron800 at googlemail.com> wrote in message 
> news:mailman.227.1196693680.2338.digitalmars-d at puremagic.com...
>> On Dec 3, 2007 2:34 PM, Craig Black <cblack at ara.com> wrote:
>>> I guess using X and Y is bad since you assume they are both types..
>>> Am I wrong in assuming the following?
>>>
>>> const X* x;
>>>
>>> is not equivalent to
>>>
>>> const(X)* x;
>>>
>>> Thus const X is not always equivalent to const(X)
>>
>> OK. Start again, You've misunderstood me. My X stands for /everything
>> between the word const and the identifier being declared/. (Not
>> literally the symbol "X").
>>
>> So I would want "const X* x" to be interchangeable with "const(X*) x",
>> since, in this case, /everything between the word const and the
>> identifier being declared/ is "X*".
>
> Right!  And the same principle can be applied to references as well.
>
> So "const X x;"  could be interpreted to be interchangeable with "const (X 
> x);"  (even though technically the latter that will not compile).
>
> Thus your const X == const(X) rule holds with "const(X) x;" and "const X 
> x;"
>

Just to expound further, the pointer and reference syntax seems difference 
since the reference is implicit.  Just think of  "const X x;" as "const X& 
x;" and you will see that the same principle that applies to pointers should 
also apply to references. 





More information about the Digitalmars-d mailing list