Re: commit: ut_vector.cpp temp build fix

From: Andrew Dunbar (hippietrail@yahoo.com)
Date: Mon Feb 10 2003 - 22:12:51 EST

  • Next message: printf scanf: "Download source code ?"

     --- "Kenneth J. Davis" <jeremyd@computer.org> wrote:
    > CVS:
    >
    ----------------------------------------------------------------------
    > CVS: Enter Log. Lines beginning with `CVS:' are
    > removed automatically
    > CVS:
    > CVS: Committing in .
    > CVS:
    > CVS: Modified Files:
    > CVS: ut_vector.cpp
    > CVS:
    >
    ----------------------------------------------------------------------
    > temp cast away const so Windows builds again
    >
    >
    > Windows fails to build, more or less due to this
    > commit:
    >
    > 1.45 hippietrail Feb 4 00:12
    > UT_Vector::addItem methods now take const void * to
    > diminish the need for casting.
    >
    > The exact error message is:
    >
    > ut_vector.cpp(146) : error C2440: '=' : cannot
    > convert from 'const void *' to 'void *'
    > Conversion loses qualifiers
    >
    >
    > The problem is that line 146
    > m_pEntries[m_iCount++] = p;
    > is assigning a now (const void *) to a (void *).
    >
    > Now I could just cast away the constness, but that
    > seems bad.
    > I could also change m_pEntries to be an array of
    > (const void *), but then the constness would have
    > to be cast away when an item is retrieved (a least
    > for some items).
    >
    > So my question for C++ experts out there, how best
    > should I fix this?
    > Should I just cast away the constness and live with
    > it, or can you suggest a more palatable way to
    > correct the build?

    Hi Kenneth. Oddly I didn't get any complaints from
    g++ even though it looks like it should've.
    But I have seen a huge amount of calls to the
    ut_vector class needing to cast away constness.
    This tells me that probably m_pEntries should be made
    const along with many of the member functions, and
    cast away const for deletion.
    It seems that the entries are not designed to be
    modifiable anyway which would support this.

    But I would also like to hear more from other C++
    experts on proper const-correctness!

    > In the meantime this patch casts (C style to
    > hopefully force someone to reply) the (const void
    > *) to a (void *) and lets the build proceed.

    I would recommend for any tricky casts to always use
    reinterpret_cast since, at least on gcc, it gives
    warnings whereas c casts do not. Thus prompting the
    hackers to look into the cause once in a while.
    Also C casts are extremely difficult to grep for
    when you're working on const-correctness.

    Andrew Dunbar.

    > Thank you,
    > Jeremy
    >
    >
    >

    =====
    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 : Mon Feb 10 2003 - 22:16:49 EST