4

I would like to know if there is an equivalent to int64_t in C that would work on 32 and 64 bits platforms and that is ansi and pedantic gcc modes compliant.

I found this interesting post, but it relates on C++.

I tried to used long long but i get an integer overflow in expression [-WOverflow] error. Moreover long long is not supported by ISO C90.

I also tried what is suggested in this post, but i still have a -WOverflow error with using int64_t

Any solutions ?

Community
  • 1
  • 1
ibi0tux
  • 2,481
  • 4
  • 28
  • 49

1 Answers1

3
  • In C89 (required by -ansi flag), there is no standard way to use a 64 bits integer. You have to rely on the types provided by your implementation.

  • In C99, some implementations may define int64_t, since it is an optional type. As for long long (C99), there is no guarantee that its width is exactly of 64 bits.

md5
  • 23,373
  • 3
  • 44
  • 93
  • I don't want to use C99. I know `long long` comes from C99 that's why i'm asking about possible equivalents in C89/C90 – ibi0tux Apr 19 '13 at 09:09
  • @ibi0tux: No, there is no standard way to do this. That's why C99 has introduced `long long` and fixed-width integers. – md5 Apr 19 '13 at 09:11
  • Do you think i can still recreate minimal fixed-length integer based on composition of fixed-length minimal structure (i.e. `char`) ? – ibi0tux Apr 19 '13 at 09:14
  • @ibi0tux: Do you mean something like `unsigned char n[8]`? Apart from the fact it would be inefficient, it is not perfectly standard, since `CHAR_BIT` could be greater than 8. It depends on the portability you want. – md5 Apr 19 '13 at 09:20
  • Ok. I suppose making my code ANSI compliant will be more difficult that i though. Thank you. – ibi0tux Apr 19 '13 at 09:23
  • `long long` is required to be *at least* 64 bits in width, so you might as well make use of that. By width, I don't mean `sizeof`; I mean the total number of *value* bits. Padding might influence the `sizeof` a type, without increasing the range that it can represent. Keep that in mind. – autistic Apr 19 '13 at 09:43