so what exactly is const supposed to mean?
brunodomedeirosATgmail at SPAM.com
Tue Jul 4 03:32:58 PDT 2006
Sean Kelly wrote:
> Bruno Medeiros wrote:
>> Sean Kelly wrote:
>>> > and doesn't D already have a const keyword?
>>> D has const as a storage attribute, which is a bit different from the
>>> above. D's const may only apply to concrete data types, and implies
>>> that the data will never be modified for the duration of the program.
>>> This allows the compiler to place such data in ROM and to perform
>>> some optimizations that would otherwise not be possible. But this is
>>> quite limited in that it may only be applied to data that can be
>>> evaluated at compile-time.
>> 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";
*(&str) = "123"; // : "ABC" is not an lvalue
Bruno Medeiros - CS/E student
More information about the Digitalmars-d-learn