user13014162
user13014162

Reputation:

Fixed 64 bit integer in Linux Kernel

I want to have a fixed size integer of 64 bits in linux kernel.

My questions:

  1. If I use unsigned long, then it may be 64-bit on one architecture and 32-bit on another. Right?
  2. What would be the data type the for fixed 64-bit integer?

I am specifically referring to linux kernel

Upvotes: 1

Views: 1624

Answers (2)

João Vitor
João Vitor

Reputation: 39

The C language provides a lot of fixed width types, signed and unsigned.

As Lundin said, "the size of unsigned long is implementation-defined and therefore non-portable".

So, common types like int, unsigned int and float depends of your compiler.

You can see a full list of available fixed width integer types since C99 in this reference

int64_t is, according to documentation, a "signed integer type with width of exactly 64 bits with no padding bits and using 2's complement for negative values".

uint64_t, also according to documentation, an "unsigned integer type with width of exactly 64 bits"

But there are more other fixed 64 bits width integer types you may be curious to see, as: uint_fast64_t, uint_least64_t

I recommend you to see the reference and have a lot of fun learning the magical C types \o/

You can also check the available types on the GNU libc manual of integer types

Hope this helps!

Upvotes: 1

Lundin
Lundin

Reputation: 213276

If I use unsigned long, then it may be 64-bit on one architecture and 32-bit on another. Right?

Yes, the size of unsigned long is implementation-defined and therefore non-portable.

What would be the data type the for fixed 64-bit integer?

int64_t or uint64_t.

Upvotes: 3

Related Questions