Size of Int on a machine

A

aruna

How do I check the size of int on a machine before
runtime, at the pre-processor stage? Is it possible?
 
E

Eric Sosman

aruna said:
How do I check the size of int on a machine before
runtime, at the pre-processor stage? Is it possible?

Not in Standard C, although some implementations allow
it as a non-conforming extension. What you *can* do, though,
is check the range of an int, using the INT_MAX and INT_MIN
macros defined in <limits.h>. For example,

#include <limits.h>
#if INT_MAX >= 1000000
typedef int Million;
#else
typedef long Million;
#endif
 
K

Kip Neuhart

aruna said:
How do I check the size of int on a machine before
runtime, at the pre-processor stage? Is it possible?

You can't do it directly in standard C. Perhaps this is a sign that your
code relies on machine specifics too much?
 
C

CBFalconer

aruna said:
How do I check the size of int on a machine before
runtime, at the pre-processor stage? Is it possible?

#include <limits.h>

#if (INT_MAX < nnnL)
# error "int too small"
#endif

It might be simpler to use longs for the appropriate variables.
 
D

Dan Pop

In said:
How do I check the size of int on a machine before
runtime, at the pre-processor stage? Is it possible?

Yup. Include <limits.h> and examine INT_MAX.

Dan
 
V

Vijay Kumar R Zanvar

aruna said:
How do I check the size of int on a machine before
runtime, at the pre-processor stage? Is it possible?

A simple method would to consult the documentation,
if any, that came with the compiler.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top