2

Is INT_MAX different between a 32-bit and 64-bit environment? It seems like it would be the case, though I've heard people say that the 64-bit environment just uses the 32-bit environment's INT_MAX.

Rio
  • 14,182
  • 21
  • 67
  • 107
  • There is no such thing like *a* 32-bit or 64-bit environment, but there are multiple definitions for each such systems. – Jens Gustedt Feb 13 '12 at 08:22

3 Answers3

6

It depends on the system. On Intel Linux they are the same. check limits.h

Anycorn
  • 50,217
  • 42
  • 167
  • 261
  • Is there a good resource I might be able to look up on understanding how they're the same on an Intel processor (and where, perhaps, they may differ instead?). Thanks! – Rio Feb 13 '12 at 08:10
  • you typically account for differences using preprocessor or by using stdint.h what is exactly u look for? – Anycorn Feb 13 '12 at 08:14
  • Trying to see what happens with underflow on an `unsigned long long int`. – Rio Feb 13 '12 at 08:15
  • http://stackoverflow.com/questions/2760502/question-about-c-behaviour-for-unsigned-integer-underflow – Anycorn Feb 13 '12 at 08:20
  • I'd say it actually depends on the compiler, which in turn is usually tuned for a specific system (CPU/OS). – Alexey Frunze Feb 13 '12 at 09:24
0

Your question is perhaps too generic, but on typical 64bit enviroment (x86-64) int is defacto the same size as on 386 (keeping in mind that this also depends on OS, not just architecture). C standard only limits lower bounds (as described on wiki).

Community
  • 1
  • 1
Tomas Pruzina
  • 8,397
  • 6
  • 26
  • 39
  • How does it depend on the OS? I'm sorry if it seemed so generic - I haven't been able to find good resources on INT_MAX in general. – Rio Feb 13 '12 at 08:07
  • When you get 32bit linux on x86-64, OS will use 32bit limits (ULOG_MAX changes for example). – Tomas Pruzina Feb 13 '12 at 08:16
0

For some compilers, there is a difference with the long type. That is, long is 32 bits when compiling for 32 bits and 64 bits otherwise, while int is 32 bits in both cases.

But depending on what you want, the answer to your question may be to use int64_t (or the equivalent for your compiler, maybe __int64 or something like that) if you want to make sure you have a 64-bit int.

So you should clarify your question.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
  • How about if I used `unsigned long long int`? Will INT_MAX differ in that case between the two environments? – Rio Feb 13 '12 at 08:15
  • No, `INT_MAX` is the maximum value of an `int`. For the maximum value of an `unsigned long long`, use `ULLONG_MAX`. But there is no guarantee that this will differ between the two "environments". It might differ, or not, depending on the situation (Windows, Linux, which compiler, etc) – Mr Lister Feb 13 '12 at 08:19