[ovs-dev] [classifier-opt 06/28] util: New macro CONST_CAST.

Ethan Jackson ethan at nicira.com
Fri Jul 27 20:38:15 UTC 2012


> Thanks.  I think it's a win on the whole too but I'm never sure
> whether the syntax is too ugly, even though I've done it this way
> before elsewhere.

I can't think of a better way to do it without compiler support.  Even
the const cast in c++ is a bit ugly.  Frankly, I think casting should
be ugly because it discourages use unless it's really necessary.

Ethan


>
> On Fri, Jul 27, 2012 at 01:33:59PM -0700, Ethan Jackson wrote:
>> Awesome, this is a huge win.  Thanks a lot.
>>
>> Ethan
>>
>> On Fri, Jul 20, 2012 at 4:25 PM, Ben Pfaff <blp at nicira.com> wrote:
>> > Casts are sometimes necessary.  One common reason that they are necessary
>> > is for discarding a "const" qualifier.  However, this can impede
>> > maintenance: if the type of the expression being cast changes, then the
>> > presence of the cast can hide a necessary change in the code that does the
>> > cast.  Using CONST_CAST, instead of a bare cast, makes these changes
>> > visible.
>> >
>> > Inspired by my own work elsewhere:
>> > http://git.savannah.gnu.org/cgit/pspp.git/tree/src/libpspp/cast.h#n80
>> >
>> > Signed-off-by: Ben Pfaff <blp at nicira.com>



More information about the dev mailing list