What is the difference between...
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Fri Sep 7 12:00:45 PDT 2007
Sean Kelly wrote:
> Bruno Medeiros wrote:
>> Janice Caron wrote:
>>> -----Original Message-----
>>> From: digitalmars-d-bounces at puremagic.com
>>> [mailto:digitalmars-d-bounces at puremagic.com] On Behalf Of Daniel919
>>> Sent: 07 September 2007 12:39
>>> To: digitalmars-d at puremagic.com
>>> Subject: Re: What is the difference between...
>>>
>>>> > (2) void f(const(int) x)
>>>> Useless, like all: const/invariant(simplestoragetype)
>>>
>>> It is? Why? Why doesn't it mean x is a const int?
>>>
>>> So f(const(int)* x) means x is a pointer to const int, but
>>> f(const(int) x) does not mean x is a const int? Now I'm very, very
>>> confused.
>>>
>>> Why am I not getting this?
>>>
>>
>> const(...) makes everything inside the parenthesis const. But there is
>> one exception: If that const is part of a declaration, then the
>> top-level value/type is not const. (the top-level value is the one
>> that changes with assignments) So:
>>
>> const(int)* x; // mutable pointer to const int
>> const(int) x; // mutable int;
>> const(int*) x; // mutable pointer to const int
>> const(int**) x; // mutable pointer to const pointer to const int;
>> const(int*)* x; // mutable pointer to const pointer to const int;
>
> Wouldn't this be "mutable pointer to mutable pointer to const int?"
>
>
> Sean
The last one :
const(int*)* x;
?
Nope, it's like I said. It can be verified with this:
x = null; // Ok
*x = null; // Error
**x = null; // Error
If people were thinking that const(<X>) would *allways* only apply
immutability to the referenced value of <X> (if X is a reference), then
that's wrong. It only does that when const(<X>) is the top-level type.
(BTW, naturally, the same is true for invariant)
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d
mailing list