Size of int

N

Nikhil Bokare

Hi,

It is said that the size of short,int,long,float and double depends on
the machine whereas the size of char is 1-byte.
Now, what do they mean by the size depends on the machine? I mean if i
have a 32-bit machine, then what will be the size of int?

Thanks.
 
K

Keith Thompson

Nikhil Bokare said:
It is said that the size of short,int,long,float and double depends on
the machine whereas the size of char is 1-byte.
Now, what do they mean by the size depends on the machine? I mean if i
have a 32-bit machine, then what will be the size of int?

The sizes of the predefined integer types depend on the compiler. The
decision of the compiler's author is likely to be guided by the
characteristics of the machine, but there can be other considerations
as well, such as compatibility with other systems.

On a 32-bit machine, the size of int will be (a) sizeof(int), by
definition, (b) whatever size the compiler writers chose, (c) *likely*
to be 32 bits, but this isn't guaranteed by the language.

See section 1 of the comp.lang.c FAQ, <http://www.c-faq.com/>.
 
L

Lew Pitcher

The sizes of the predefined integer types depend on the compiler. The
decision of the compiler's author is likely to be guided by the
characteristics of the machine, but there can be other considerations
as well, such as compatibility with other systems.

On a 32-bit machine, the size of int will be (a) sizeof(int), by
definition, (b) whatever size the compiler writers chose, (c) *likely*
to be 32 bits, but this isn't guaranteed by the language.

And (d) large enough to hold a value of INT_MAX
 
F

Flash Gordon

Nikhil Bokare wrote, On 12/06/07 19:22:
Hi,

It is said that the size of short,int,long,float and double depends on
the machine whereas the size of char is 1-byte.
Now, what do they mean by the size depends on the machine?

Exactly what it says. Actually, it depends on the implementation since
sometimes there are different compilers (or the same compiler with
different options) where the size of some of these things are different.
> I mean if i
have a 32-bit machine, then what will be the size of int?

That depends on what you mean by a 32 bit machine and the size of a
byte. This is not just quibbling, I've used processors with 16 bit
bytes, others here have used processors with 32 bit bytes. So a 32 bit
int could be as small as 1 byte or as large as 4 (assuming no padding).
Or you could have a 32 bit processor but a compiler which provides a 16
bit int, and yes this does happen.
 
K

Kenneth Brody

Flash said:
Nikhil Bokare wrote, On 12/06/07 19:22: [...]
I mean if i
have a 32-bit machine, then what will be the size of int?

That depends on what you mean by a 32 bit machine and the size of a
byte. This is not just quibbling, I've used processors with 16 bit
bytes, others here have used processors with 32 bit bytes.

And, on these systems, it's possible that chars were 16 or 32 bits,
yet sizeof(char) is still, by definition, one.
So a 32 bit
int could be as small as 1 byte or as large as 4 (assuming no padding).
Or you could have a 32 bit processor but a compiler which provides a 16
bit int, and yes this does happen.

And, nowadays, a "64 bit processor" with a 32-bit int. (Or even a
16-bit int, though this is not likely if using a "modern" compiler
targeted to that platform.)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 

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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top