By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

Strange warning with deque.

P: n/a
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<TempHumDataTempHumDeque; // 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/

Jul 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
* Robbie Hatley:
>
My OS is Windows 2000, and my compiler is Visual C++ 6.0.
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.
Jul 4 '06 #2

P: n/a
"Robbie Hatley" <bo*********@no.spam.comwrote in message
news:vQ********************@newssvr21.news.prodigy .com...
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?
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
Jul 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.