Clarifying 'const' terminology
Bruno Medeiros
brunodomedeirosATgmail at SPAM.com
Sat Jul 8 14:03:15 PDT 2006
Deewiant wrote:
> Bruno Medeiros wrote:
>> There are some variations in const semantics. In C++, const is a
>> type-modifier, meaning that const can be applied to each type element,
>> and not the "variable as whole". Best to give an example. In C++ you can
>> have:
>> const int * iptr = ...;
>> int const * iptr = ...;
>> const int const * iptr = ...;
>> each with different meanings:
>>
>> const int * iptr = ...;
>> // cannot modify the pointed int, can modify the pointer
>>
>> int const * iptr = ...;
>> // can modify the pointed int, cannot modify the pointer (the pointer
>> is const)
>>
>> const int const * iptr = ...;
>> // Cannot modify the pointed int, nor cannot modify the pointer
>>
>
> Actually, the former two are equivalent. To clarify (equivalent types are paired
> on one line):
>
> const int, int const
> const int *, int const *
> const int * const, int const * const
> int * const
>
Oops, that's right, thanks for correcting me. I should have tested it,
it's not the first time it got const declarations mixed up, damn C++ ... :p
--
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d-learn
mailing list