Is it possible that converting from size_t to unsigned int result in overflow .
size_t x = foo ( ) ; // foo ( ) returns a value in type size_t
unsigned int ux = (unsigned int ) x ;
ux == x // Is result of that line always 1 ?
language : c++
platform : any
Yes it’s possible,
size_tandintdon’t necessarily have the same size. It’s actually very common to have 64bitsize_ts and 32bitints.C++11 draft N3290 says this in §18.2/6:
unsigned inton the other hand is only required to be able to store values from 0 toUINT_MAX(defined in<climits>and following the C standard header<limits.h>) which is only guaranteed to be at least 65535 (216-1).