By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 1,552 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

Size of int

P: n/a
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.

Jun 12 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Nikhil Bokare <nb*****@gmail.comwrites:
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/>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 12 '07 #2

P: n/a
On Jun 12, 3:10 pm, Keith Thompson <k...@mib.orgwrote:
Nikhil Bokare <nbok...@gmail.comwrites:
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.
And (d) large enough to hold a value of INT_MAX
See section 1 of the comp.lang.c FAQ, <http://www.c-faq.com/>.


Jun 12 '07 #3

P: n/a
Lew Pitcher <lp******@teksavvy.comwrites:
On Jun 12, 3:10 pm, Keith Thompson <k...@mib.orgwrote:
[...]
>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
Which is guaranteed to be at least 32767.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 12 '07 #4

P: n/a
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.
--
Flash Gordon
Jun 12 '07 #5

P: n/a
Flash Gordon wrote:
>
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:Th*************@gmail.com>

Jun 13 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.