简体   繁体   中英

C++: Is it safe to compare a 64bit integer with a 32bit integer?

Assuming I have 2 variables:

uint64_t a = ...

uint32_t b = ...

Will comparing the integers yield the expected results, ie (a != b) , or (b > a) ?

No problem. The compiler promotes the 32-bit to 64-bit before the comparison

Short answer - yes. The 'smaller' is converted to bigger one before comparison.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM