zer0stimulus
zer0stimulus

Reputation: 23606

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, i.e. (a != b), or (b > a)?

Upvotes: 18

Views: 4359

Answers (2)

nothrow
nothrow

Reputation: 16168

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

Upvotes: 8

user206545
user206545

Reputation:

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

Upvotes: 27

Related Questions