Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

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)?

like image 839
zer0stimulus Avatar asked Apr 11 '12 20:04

zer0stimulus


People also ask

Is int always 32 bits in C?

int is always 32 bits wide. sizeof(T) represents the number of 8-bit bytes (octets) needed to store a variable of type T .

What is 64-bit integer in C?

The long long data type makes handling 64 bit integers easy. In C language, an unsigned number over 32 bits cannot exceed the value of 4,294,967,295. You may find you are required to handle larger numbers and for this you need these numbers to be coded in 64-bit.

What is 64-bit integer data type?

A 64-bit signed integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). A 64-bit unsigned integer. It has a minimum value of 0 and a maximum value of (2^64)-1 (inclusive).


1 Answers

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

like image 81
sizzzzlerz Avatar answered Oct 16 '22 04:10

sizzzzlerz