Re: I Hate Warnings! This One Has Me.



Painful, isn't it? size_t is defined as:

typedef unsigned int _w64 size_t;

which means it will go to 64 bits in 64-bit systems, and so the warning
should apply. However, when this is used as a template parameter, it appears
that _w64 is erased, so vector<size_t> is equivalent to vector<unsigned
int>...

I usually wind up doing

typedef std::vector<size_t>::value_type SizeVectorValueType;

and you can then happily do:

m_keys[pd.px()] = static_cast< SizeVectorValueType >( m_products.size() );

as a particularly ugly workaround.
--
David

"Arnie" <none> wrote in message
news:OXM6szFlFHA.3628@xxxxxxxxxxxxxxxxxxxxxxx
> Help, or at least an explanation, will be appreciated.
>
> I'm porting a program from Borland to VC++ v8 beta 2. The warning occurs
> with the /wp 64 switch turned on, apparently due to size differences
> between (unsigned) int and size_t on 32 and 64 bit systems. I understand
> that difference, but can't make much sense out of the warning. Code
> snippets:
>
> In class TProductData:
>
> // *** Accessors ***
>
> inline int px(void) const {return m_px;}
>
> private:
>
> int m_px;
>
> In class TProductHash:
>
> inline void insert(const TProductData &pd)
>
> {
>
> //*** Warning on the following line ***
>
> m_keys[pd.px()] = m_products.size();
>
> m_products.push_back(pd);
>
> }
>
> private:
>
> std::vector<size_t> m_keys;
>
> The warning is:
>
> warning C4267: '=' : conversion from 'size_t' to 'unsigned int', possible
> loss of data
>
> Where the dickens did "unsigned int" come from, other than being a typedef
> for size_t?
>
> Thanks for any help
>
> - Arnie
>
>
>
>


.