1

I know that in Unixes/Linuxes the long size is 64bit.

But when using the same under the windows (x64) the long is always 32bit.

Is there any workaround/library that enable the use of larger integers in C ?

Mansueli
  • 6,223
  • 8
  • 33
  • 57
  • 1
    In C++ we use `long long`, not 100% certain that applies to C. (I normally use `size_t` and `ptrdiff_t` if I need something that toggles depending on the build) – Mooing Duck May 20 '14 at 20:24
  • 5
    Bear in mind that the size of types also depends on the compiler, so there may be a compiler that uses a 64 bit `long` type. – kevintodisco May 20 '14 at 20:25
  • Yep, it is a compiler thing not an operating system thing...but the problem was solved a long long time ago... – old_timer May 20 '14 at 20:26
  • 2
    Try `#include `, then use `int64_t`. – hyde May 20 '14 at 20:31

1 Answers1

5

Under C99, you have two possibilities

  • Use long long, since it is required to be at least 64-bit
  • If available, use int64_t, or int_least64_t, from stdint.h

In the second approach, you may find it useful to combine with inttypes.h, which adds portable formatting and conversion functions, but note that while stdint.h is required in both hosted and freestanding implementations, inttypes.h is only required in hosted implementations.

Also, exactly which types are defined in stdint.h is implementation-defined in some cases, but if a type is defined, then both signed and unsigned versions must exist.

Filipe Gonçalves
  • 20,783
  • 6
  • 53
  • 70