424,987 Members | 1,552 Online
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
5 Replies

 P: n/a Nikhil Bokare . -- Keith Thompson (The_Other_Keith) ks***@mib.org San Diego Supercomputer Center <* "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 . Jun 12 '07 #3

 P: n/a Lew Pitcher On a 32-bit machine, the size of int will be (a) sizeof(int), bydefinition, (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 San Diego Supercomputer Center <* "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 | Jun 13 '07 #6

### This discussion thread is closed

Replies have been disabled for this discussion.