This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Optimizing


On 30 January 2011 20:40, Enrico Weigelt wrote:
> * Kalle Olavi Niemitalo <kon@iki.fi> wrote:
>
>> Although the second parameter is const void *, the language still
>> allows the function to modify the object to which that points,
>> provided that the object was not defined as const.
>
> Doesn't that defeat the whole purpose of const ?

No. http://www.gotw.ca/gotw/081.htm


> BTW: let me add another question:
>
>
> ? ?const std::string str;
>
> ? ?void one(const std::string s)
> ? ?{
> ? ? ? ?str = s;
> ? ?}
>
> ? ?void two(const char* s)
> ? ?{
> ? ? ? ?one(s);
> ? ?}
>
> ? ?void three()
> ? ?{
> ? ? ? ?two("hello world");
> ? ?}
>
>
> What actually happens here under the hood ? Is this reliable ?
> (lifetime of the string object)

It won't compile because you assign to a const, so I don't understand
the question.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]