Re: const_cast question

From: Bill Seurer (seurer_at_us.ibm.com)
Date: 05/05/04


Date: Wed, 05 May 2004 07:29:57 -0500

George Privalov wrote:

> Bill Seurer <seurer@us.ibm.com> wrote in message news:<c7801c$1e8q$1@news.rchland.ibm.com>...
>
>>People want their code to be as fast as possible so they throw in all
>>the "tricks" they have learned (or just heard of) to make it faster even
>>if their code breaks the "contract" that those tricks require. It's
>>fairly obviously for something like this but a lot trickier other times.
>> I see this quite frequently with the aliasing rules and optimization
>>in my compiler work.
>
>
> I can not come up with one example when casting away constness should
> improve the code's performance.

No, no. The other way round. They stick in const thinking it makes the
code faster and then break it by casting away const because the stuff
really wasn't const to begin with.



Relevant Pages

  • Re: Why is the kfree() argument const?
    ... Any idea how to convince gcc that this is okay? ... Either don't use a broken compiler (casting a const pointer to a non-const ...
    (Linux-Kernel)
  • Re: Is this legal ?
    ... >> to be followed again if the compiler can't guarantee that nothing that ... >address of an object into a pointer to const type version, ... to change it (by casting away const from a pointer to it, ...
    (comp.lang.c)
  • Re: Writing single bits to a file
    ... To be honest I'll use const wherever I can, unless it's stupid (and by ... If I take a pointer as an argument to a function, ... Just like casting strcpy to and casting the result of malloc. ...
    (comp.lang.c)
  • Re: const_cast, reinterpret_cast
    ... Also for casting from non-const to const, and volatile to non-volatile, ...
    (comp.lang.cpp)
  • Re: const_cast question
    ... "Jeff Schwab" wrote in message ... > George Privalov wrote: ... > The compiler can sometimes assume cached values have not been modified ... > if the corresponding variables have been declared const. ...
    (comp.lang.cpp)