Strange warning with deque.

Discussion in 'C++' started by Robbie Hatley, Jul 4, 2006.

  1. I'm getting a strange warning at work when I compile any file in our
    product that contains a deque of a particular struct. I don't understand
    this warning, so I'm not sure if this is a Microsoft Windows issue, or
    a C++ issue, so I'm posting it both to a Windows group and to a C++
    group.

    My OS is Windows 2000, and my compiler is Visual C++ 6.0.

    The warning I'm getting is this:

    c:\program files\microsoft visual studio\vc98\include\deque(107) :
    warning C4146: unary minus operator applied to unsigned type,
    result still unsigned
    c:\program files\microsoft visual studio\vc98\include\deque(104) :
    while compiling class-template member function
    'void __thiscall std::deque<struct RT::TempHumData,
    class std::allocator<struct RT::TempHumData> >::const_iterator::_Add(int)'

    The problem seems to occur when instantiating std::deque<TempHumArray>.
    The problem is with the "_Add()" function in std::deque. For some
    reason, it attempts to do a unary minus on a unsigned type:

    protected:
    void
    _Add(difference_type _N)
    {
    difference_type _Off = _N + _Next - _First;
    difference_type _Moff = (0 <= _Off)
    ? _Off / _DEQUESIZ
    : -((_DEQUESIZ - 1 - _Off) / _DEQUESIZ); // WARNING!!!
    if (_Moff == 0)
    _Next += _N;
    else
    {
    _Map += _Moff;
    _First = *_Map;
    _Last = _First + _DEQUESIZ;
    _Next = _First + (_Off - _Moff * _DEQUESIZ);
    }
    }

    What's this "_Add()" function doing, anyway? To me, it looks like
    some kind of pointer arithmetic, possibly implimenting subscripting.

    The struct I'm storing in the deque is very simple:

    struct TempHumData
    {
    TempHumData() : TimeStamp(0), Temp(0.0), Hum(0.0), Stage (0) {}
    time_t TimeStamp; // VC++6 typedefs "time_t" to "long"
    double Temp;
    double Hum;
    short Stage;
    };

    The only place where this is put into a deque is in this struct:

    struct ZoneRTData
    {
    // Constructor (default or parameterized)
    ZoneRTData (const ::zone& Zone = ::zone())
    : Disabled(false), Stage(0), Load(0), DbData(Zone) {}

    // Database data:
    ::zone DbData;

    // Zone deadband verification values:
    deque<TempHumData> TempHumDeque; // temperature/humidity history deque

    // Zone disable/enable control values:
    bool Disabled; // zone-disable flag; true if zone is disabled

    // ACP/AHP exponential upstage boost control values:
    ZoneLoadBoostData ZoneBoost;

    // ACP/AHP hysteresis contol values:
    short Stage; // historical stage setting...
    short Load; // historical load setting...
    };

    Objects of this type are put in a global map of ZoneRTData objects keyed by
    unsigned int object ID numbers.

    So... why am I getting this weird "unary minus on unsigned type" warning?
    Is this a VC++6.0 thing? Or a C++ thing? Is there something bad I'm
    doing in my code that is causing this?


    --
    Cheers,
    Robbie Hatley
    Tustin, CA, USA
    lonewolfintj at pacbell dot net
    (put "[usenet]" in subject to bypass spam filter)
    http://home.pacbell.net/earnur/
     
    Robbie Hatley, Jul 4, 2006
    #1
    1. Advertisements

  2. * Robbie Hatley:
    Upgrade to either MSVC 7.1 (free with Visual C++ Toolkit) or MSVC 8.0
    (free with Visual Studio Express). Or use some other compiler such as
    g++. MSVC 6.0 is very old and does not support template code very well.
     
    Alf P. Steinbach, Jul 4, 2006
    #2
    1. Advertisements

  3. Robbie Hatley

    P.J. Plauger Guest

    The strange warning was added in a service pack, long after the library
    code froze. It is indeed just a warning, and a misguided one at that.
    The code is correct.

    P.J. Plauger
    Dinkumware, Ltd.
    http://www.dinkumware.com
     
    P.J. Plauger, Jul 4, 2006
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.