Reputation: 40947
All this originated from me poking at a compiler warning message (C4267) when attempting the following line:
const unsigned int nSize = m_vecSomeVec.size();
size()
returns a size_t which although typedef'd to unsigned int, is not actually a unsigned int. This I believe have to do with 64 bit portability issues, however can someone explain it a bit better for me? ( I don't just want to disable 64bit warnings.)
Upvotes: 1
Views: 1721
Reputation: 13973
When compiling for a 64-bit platform, size_t
will be a 64-bit type. Because of this, Visual Studio gives warnings about assigning size_t
s to int
s when 'Detect 64-bit Portability Issues' is enabled.
Visual C++ gets this information about size_t
through the __w64
token, e.g. __w64 unsigned int
.
Refer the below link for more on 64 bit porting issues.. http://www.viva64.com/en/a/0065/
Upvotes: 3
Reputation: 506965
It depends on the implementation. std::size_t
for example has a minimal required size. But there is no upper limit. To avoid these kind of situations, always use the proper typedef:
const std::vector<T>::size_type nSize = m_vecSomeVec.size();
You will be always on the safe side then.
Upvotes: 8
Reputation: 399823
If size_t
is typedef:ed to unsigned int
, then of course it is an unsigned int
, on your particular platform. But it is abstracted so that you cannot depend on it always being an unsigned int
, it might be larger on some other platform.
Probably it has not been made larger since it would cost too much to do so, and e.g. vectors with more than 2^32 items in them are not very common.
Upvotes: 2