Reputation: 49
Is there any reason not to assume that SIZE_T is a typedef of size_t on Microsoft's Visual C/C++ compilers ? The Windows intsafe.h functions do include safe casting functions from one to the other. Is that just for the sake of completeness or is there any scenario where a static cast could fail to give the expected result ?
Upvotes: 1
Views: 357
Reputation: 69682
If your application have to be cross-platform, then you'll have to use only what's standard in the language, that is std::size_t. Otherwise, use what seems to fit. If your goal is to get a type that is std::size_t, then why not use it directly and not care about the platform specific types?
By the way, std::size_t is guaranteed to provide enough values for the maximum array size, that is the maximum bytes that can be allocated on the computer. So it should be safe to use it instead of any other typedef.
Upvotes: 4
Reputation: 59563
Given that the only documentation is vague to say the least, I would steer clear of assuming much of anything about the relationship between SIZE_T
and size_t
. As long as SIZE_T
is a typedef
to an integral type, then static_cast<std::size_t>(val)
should work as expected.
Upvotes: 2