64 bit portability issues
This all came from me trying to squeeze out a compiler warning (C4267) when trying to execute the following line:
const unsigned int nSize = m_vecSomeVec.size();
size()
returns size_t, which, although typedef'd for unsigned int, is not actually unsigned int. I suppose this is due to 64-bit portability issues, however can someone please explain me a little better for me? (I don't just want to disable 64-bit warnings.)
source to share
When compiled for a 64-bit platform, it size_t
will be 64-bit. Because of this, Visual Studio gives warnings about the assignment size_t
to to int
when Detect 64-bit Portability Issues is enabled.
Visual C ++ gets this information about size_t
through a token __w64
, eg. __w64 unsigned int
...
Refer to the link below for more information on 64-bit port issues. http://www.viva64.com/en/a/0065/
source to share
If size_t
is typedef: ed before unsigned int
, then of course it's unsigned int
on your specific platform. But it is abstracted so that you cannot depend on it all the time unsigned int
, it can be more on some other platform.
It probably wasn't zoomed in as it would cost too much to do this, and for example vectors with more than 2 ^ 32 elements in them are not very common.
source to share