so what exactly is const supposed to mean?
Bruno Medeiros
brunodomedeirosATgmail at SPAM.com
Wed Jul 5 05:02:26 PDT 2006
Sean Kelly wrote:
> Bruno Medeiros wrote:
>> Sean Kelly wrote:
>>> Bruno Medeiros wrote:
>>>>
>>>> There is a slight difference from D's const and a const that places
>>>> the data in ROM as you cannot get the address of a D const var (it's
>>>> not an lvalue).
>>>
>>> Ever tried taking the address of a const string? That you can't take
>>> the address of other const types is simply a result of optimization.
>>>
>>
>> I tried it now, and the const string also can't be taken an address from:
>>
>> const char[] str = "ABC";
>>
>> void func()
>> {
>> *(&str) = "123"; // : "ABC" is not an lvalue
>> }
>
> That's interesting. I would have expected all strings to live in a
> static data segment. And in fact they seem to, though initialization
> seems to happen in a slightly weird manner:
>
Yes, they have to live in a static data segment. But does that change
anything? The value of "ABC" is already the address of the string, thus
&"ABC" is not valid. (akin to &(&somevar) )
--
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d-learn
mailing list