Re: Commit: fix casting problems

From: Andrew Dunbar (hippietrail@yahoo.com)
Date: Wed Feb 05 2003 - 20:59:25 EST

  • Next message: Andrew Dunbar: "Re: GNOME HIG and libglade2"

     --- Dom Lachowicz <domlachowicz@yahoo.com> wrote:
    > Someone changed a bunch of C casts to C++ casts last
    > night, which caused a slew of warnings and errors,
    > at least on Linux with GCC 3.2 and 2.95. I'm all in
    > favor of C++ casts, but in the future, please use
    > them correctly. static_cast is no panacea. Please
    > remember our friends reinterpret_cast and
    > const_cast as well, or at least remember that GCC
    > doesn't like things
    > like:
    >
    > void ** foo = static_cast<void **>(const char **)
    >
    > Fixes committed. No harm done.

    Hi Dom. I expected this sooner or later and meat to
    post a warning and explanation to the list but I run
    out of time.
    Basically I'm going through all the Unix and XP source
    file by file and doing the conversions
    semi-automatically by hand. Then I'm recompiling to
    test them.
    But inevitably there's going to be cases where I
    changed code that's not in my build for various
    reasons and that's hard to spot without slowing down
    my work significantly.
    So I'll just ask everybody to be patient and to fix
    any broken casts with proper C++ casts and resist the
    temptation to put back the old C casts.
    I apologize for any inconvenience but hopefully the
    breakages will be rare and easily fixed but feel free
    to flame me off list anyway if it makes you feel
    better (:

    To make the work as quick as possible, this is the way
    I'm doing it:

    1) Grep for C casts (difficult but I catch most)
    2) Dumbly convert C cast to static_cast
    3) Save file when all casts converted
    4) Rebuild
    5) Fix any dumb static_cast to reinterpret_cast or
       const_cast (or sometimes both!)
    6) Fix any warnings
    7) goto 3)

    Sometimes at step 2) I can see easily that some other
    cast is the right thing the first time.

    If you still feel the need to use C casts, please read
    up on C++ casts. They're less ambiguous, they can
    sometimes help optimization, and sometimes even
    prevent subtle errors.
    If you want to convert your casts but are not sure of
    the exact casts you should use, following the steps
    above *usually* works.

    Thanks for your patience while I'm unable to do any
    more significant coding... Andrew Dunbar.

    =====
    http://linguaphile.sourceforge.net/cgi-bin/translator.pl http://www.abisource.com

    __________________________________________________
    Do You Yahoo!?
    Everything you'll ever need on one web page
    from News and Sport to Email and Music Charts
    http://uk.my.yahoo.com



    This archive was generated by hypermail 2.1.4 : Wed Feb 05 2003 - 21:02:47 EST