473,413 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Size of int

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 39219
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Marti | last post by:
Dear everyone, Its my understanding that IE6 now uses a default text-size of "Small" rather than IE5's "Medium". Since I have used relative font-sizes (usually in ems) on all my sites, I am...
25
by: Matthias | last post by:
Hi, I am just reading that book by Scott Meyers. In Item 4 Meyers suggests to always use empty() instead of size() when probing for emptyness of STL containers. His reasoning is that size()...
9
by: Dr John Stockton | last post by:
Assuming default set-ups and considering all reasonable browsers, whatever that may mean, what should an author expect that his readers in general will see (with visual browsers) for a page with...
2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
27
by: Deephay | last post by:
Greetings all, I have a program that used the realloc() function to change the allocated size of a buffer, the program works with some arguments, but with some other arguments, it will show me...
8
by: redefined.horizons | last post by:
I would like to have an array declaration where the size of the array is dependent on a variable. Something like this: /* Store the desired size of the array in a variable named "array_size". */...
7
by: carterweb | last post by:
This is how I do it now. 1. Determine the dimensions of the rectangle. 2. Set a my font size to a fixed maximum size. 3. Apply the font my string and measure the string using the graphics...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
27
by: 1001 Webs | last post by:
I am trying to make my style sheet as compatible as possible and I'm getting a bit confused here. I've read that the best size for font-size would be 76.1%; due to shortcomings in the way both...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.