Should I use long long or int64_t for portable code?

后端 未结 3 2278
臣服心动
臣服心动 2020-12-15 03:03

I have an open-source codebase that is written in both C and C++. I\'m looking for an integer type that is guaranteed to be at least 64 bits wide, which can be reli

3条回答
  •  一整个雨季
    2020-12-15 03:30

    Is the general suggestion to use int64_t in place of long long, when portability is an important goal?

    I'd be very surprised if a compiler offered int64_t but not long long.

    If long long is present, it must have at least 64 bits, so casting from (u)int64_t to (unsigned) long long is value-preserving.

    If you need a type with exactly 64 bits, use (u)int64_t, if you need at least 64 bits, (unsigned) long long is perfectly fine, as would be (u)int_least64_t.

提交回复
热议问题