473,323 Members | 1,574 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,323 software developers and data experts.

size of integer

N869, page 35 -->

"A ''plain'' int object has the natural size suggested by the
architecture of the execution environment (large enough to contain any
value in the range
INT_MIN to INT_MAX as defined in the header <limits.h>). "

How do we decide the value of INT_MIN and INT_MAX ? Does the
compiler refers to this value to determine the size of int ?

Are these values always fixed for a specific platform and who
decides these values ?

Nov 15 '05 #1
8 2336
ju**********@yahoo.co.in wrote:
N869, page 35 -->

"A ''plain'' int object has the natural size suggested by the
architecture of the execution environment (large enough to contain any
value in the range
INT_MIN to INT_MAX as defined in the header <limits.h>). "

How do we decide the value of INT_MIN and INT_MAX ?
_We_ don't. The implementation does (mostly, it takes whatever
has been given by the OS in order to work with existing libraries
but it can do as it wants).
Does the
compiler refers to this value to determine the size of int ?
Probably not. "sizeof (int) * CHAR_BIT" might be much larger
than needed due to padding bits.
Are these values always fixed for a specific platform and who
decides these values ?


See above. Usually, the platform gives preference to a certain
size in bits which usually becomes int. It may even support
padding bits for certain operations. However, the compiler's
implementor (provided that control over the standard library
is given) can freely choose within the numerical limits
given by the standard.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #2
ju**********@yahoo.co.in writes:
N869, page 35 -->

"A ''plain'' int object has the natural size suggested by the
architecture of the execution environment (large enough to contain any
value in the range
INT_MIN to INT_MAX as defined in the header <limits.h>). "

How do we decide the value of INT_MIN and INT_MAX ? Does the
compiler refers to this value to determine the size of int ?

Are these values always fixed for a specific platform and who
decides these values ?


The <limits.h> header (which defines INT_MIN and INT_MAX) and the
compiler (which implements type int) are both part of the
implementation. They just have to be consistent with each other, and
with the requirements in the standard.

The values are decided by whoever is responsible for the
implementation. If there are multiple C implementations for a given
platform, the characteristics of the predefined types are commonly the
same across implementations, but the standard doesn't require it.

--
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.
Nov 15 '05 #3
ju**********@yahoo.co.in wrote on 02/08/05 :
How do we decide the value of INT_MIN and INT_MAX ? Does the
compiler refers to this value to determine the size of int ?

Are these values always fixed for a specific platform and who
decides these values ?


They are platform-dependent. The implementer decides in accordance with
the features of the achitecture.

x86 real mode is 16-bit oriented
x86 protected mode is 32-bit oriented
68000 is 32-bit oriented
etc.

8051 is 8-bit oriented, that makes it a bad candidate for a
C-implementation, but with the help of external libraries (and poor
performances), implementations of C for 8051 exists (Keil etc.)
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"It's specified. But anyone who writes code like that should be
transmogrified into earthworms and fed to ducks." -- Chris Dollin CLC
Nov 15 '05 #4

<ju**********@yahoo.co.in> wrote
How do we decide the value of INT_MIN and INT_MAX ? Does the
compiler refers to this value to determine the size of int ?
The size of an int will be built into the compiler and be reflected in very
many places, such as the machine code it emits for basic operations.
INT_MIN and INT_MAX are written into limits.h, probably just before
shipping, so that the C programmer has access to the size of an integer. You
can't force a compiler to use a different size by editing these values.
Are these values always fixed for a specific platform and who
decides these values ?

int is meant to be the "natural integer size". On some machines this is
perfectly obvious. For instance many machines have 32 bit registers, and can
only implement longer or shorter integers with bit masking. Other times it
is less clear - for instance a 64 bit machine should arguably have 64-bit
ints, but many of the operations may be more efficent using halfwords of 32
bits. In these cases the compiler writer will decide what makes most sense
for his intended users - a games console compiler writer may make a
different decision to a compiler writer who is selling to engineering users.
Nov 15 '05 #5

Malcolm wrote:
<ju**********@yahoo.co.in> wrote
How do we decide the value of INT_MIN and INT_MAX ? Does the
compiler refers to this value to determine the size of int ?

The size of an int will be built into the compiler and be reflected in very
many places, such as the machine code it emits for basic operations.
INT_MIN and INT_MAX are written into limits.h, probably just before
shipping, so that the C programmer has access to the size of an integer. You
can't force a compiler to use a different size by editing these values.

<snip>

You mean to say, that the file "limits.h" will be shipped as a part
of C compiler ?

Nov 15 '05 #6
ju**********@yahoo.co.in wrote on 03/08/05 :
You mean to say, that the file "limits.h" will be shipped as a part
of C compiler ?


Sure, with at last a dozen of other headers...

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"It's specified. But anyone who writes code like that should be
transmogrified into earthworms and fed to ducks." -- Chris Dollin CLC
Nov 15 '05 #7
ju**********@yahoo.co.in wrote:

You mean to say, that the file "limits.h" will be shipped as a part
of C compiler ?


Well, to be a C compiler it must provide the header <limits.h>. From
the C99 draft standard:
[#2] The standard headers are

<assert.h> <inttypes.h> <signal.h> <stdlib.h>
<complex.h> <iso646.h> <stdarg.h> <string.h>
<ctype.h> <limits.h> <stdbool.h> <tgmath.h>
<errno.h> <locale.h> <stddef.h> <time.h>
<fenv.h> <math.h> <stdint.h> <wchar.h>
<float.h> <setjmp.h> <stdio.h> <wctype.h>
There's no requirement that the header be a separate file, but that's
pretty typical.

Brian
Nov 15 '05 #8
ju**********@yahoo.co.in writes:
Malcolm wrote:
<ju**********@yahoo.co.in> wrote
> How do we decide the value of INT_MIN and INT_MAX ? Does the
> compiler refers to this value to determine the size of int ?
>

The size of an int will be built into the compiler and be reflected in very
many places, such as the machine code it emits for basic operations.
INT_MIN and INT_MAX are written into limits.h, probably just before
shipping, so that the C programmer has access to the size of an integer. You
can't force a compiler to use a different size by editing these values.
>

<snip>

You mean to say, that the file "limits.h" will be shipped as a part
of C compiler ?


Maybe.

The standard headers (which may or may not be implemented as files),
the implementation of the standard library functions, the compiler,
the linker, and whatever else is required to support them are all part
of "the implementation". How all these parts are assembled into a
conforming C implementation, and in particular how anything is
"shipped", is not specified by the standard. If the limits.h header
is provided separately from the compiler, that's just fine as long as
everything is consistent.

--
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.
Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Shailesh | last post by:
One problem I've been wrestling with for a long time is how to use the C++ integral data types, vis-a-vis their size. The C++ rules guarantee that a char is at least 1 bytes, a short and int at...
5
by: Brian DSouza | last post by:
I got the following code from an earlier posting (much earlier, like 1999) in this ng. This is supposed to control the paper size selected to legal, even if the default printer changes. Question is...
33
by: siliconwafer | last post by:
What is size of pointer in C on DOS? is it sizeof(int ) or size of (long int)? If this ans is present in FAQ pls direct me to tht ouestion
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...
4
by: Shayne H | last post by:
How can I create a structure that gets passed to an API call that will automatically set its size field? I tried the following: <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _...
5
by: Francois Soucy | last post by:
Hi all! I've created a personal control. This control is mainly a panel with some other stuff in. I want to know if it's possible to know the size of the container of this control? I mean that my...
12
by: J L | last post by:
When I fill a listview, I resize the columns to fit the data. I need to know if the data will fit vertically or if there will be a vertical scroll bar. I need to know this so I can allow for it on...
6
by: marktxx | last post by:
Although the C90 standard only mentions the use of 'signed int' and 'unsigned int' for bit-fields (use 'int' at your own risk) and C99 adds _Bool. It seems that most compilers create the size of...
36
by: James Harris | last post by:
Initial issue: read in an arbitrary-length piece of text. Perceived issue: handle variable-length data The code below is a suggestion for implementing a variable length buffer that could be used...
6
by: Miro | last post by:
Is there a way to / or a mathematical formula to see if a font size is 'too big' for a label. I have a label that is docked to 'fill' a form, and I want to resize that font based on the width...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.