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

minimum and maximum values of an object of type int

Guys,

Does the standard allow to an implementation to chose any maximum
and minimum value for an object of type int ?

For eg. Can an implementation with sizeof(int)=4, chose to have value
of
INT_MAX = 2147483646 (in limits.h).

Or it is mandatory that if sizeof(int)=4, then the INT_MAX should have
to be
equal to 2147483647 and INT_MIN should have to be equal to (-
INT_MAX-1).

Again, thanks a lot for any help.

Sep 14 '07 #1
7 3590
ju**********@yahoo.co.in said:
Guys,

Does the standard allow to an implementation to chose any maximum
and minimum value for an object of type int ?
No.

Let's first deal with the minimal range.

INT_MIN must be at most -32767 (but can be lower - or, if you prefer,
may have a higher absolute value, but must still be negative). INT_MAX
must be at least 32767 (but can be higher).

Now let's deal with this:
For eg. Can an implementation with sizeof(int)=4, chose to have value
of
INT_MAX = 2147483646 (in limits.h).
No. An int must comprise one sign bit, at least fifteen value bits (but
more are allowed), and 0 or more "padding bits". INT_MAX must therefore
be exactly one less than a power of two. INT_MIN must be negative, of
course, but its absolute value might reasonably be a power of two (the
same power as for INT_MAX), or one less than that power of two. Thus,
if there are fifteen value bits, INT_MIN must be -32767 or -32768.
Or it is mandatory that if sizeof(int)=4, then the INT_MAX should have
to be
equal to 2147483647 and INT_MIN should have to be equal to (-
INT_MAX-1).
No, because padding bits contribute to the size of the int. Thus, it is
possible, where CHAR_BIT is 8 and sizeof(int) is 4, for there to be
anywhere from 0 to 16 padding bits, and thus INT_MIN could be anything
from -32767 to -2147483648. Under the same constraints, INT_MAX could
be anything from 32767 to 2147483647.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 14 '07 #2
On Sep 14, 3:31 pm, Richard Heathfield <r...@see.sig.invalidwrote:
junky_fel...@yahoo.co.in said:
Guys,
Does the standard allow to an implementation to chose any maximum
and minimum value for an object of type int ?

No.

Let's first deal with the minimal range.

INT_MIN must be at most -32767 (but can be lower - or, if you prefer,
may have a higher absolute value, but must still be negative). INT_MAX
must be at least 32767 (but can be higher).

Now let's deal with this:
For eg. Can an implementation with sizeof(int)=4, chose to have value
of
INT_MAX = 2147483646 (in limits.h).

No. An int must comprise one sign bit, at least fifteen value bits (but
more are allowed), and 0 or more "padding bits". INT_MAX must therefore
be exactly one less than a power of two. INT_MIN must be negative, of
course, but its absolute value might reasonably be a power of two (the
same power as for INT_MAX), or one less than that power of two. Thus,
if there are fifteen value bits, INT_MIN must be -32767 or -32768.
Or it is mandatory that if sizeof(int)=4, then the INT_MAX should have
to be
equal to 2147483647 and INT_MIN should have to be equal to (-
INT_MAX-1).

No, because padding bits contribute to the size of the int. Thus, it is
possible, where CHAR_BIT is 8 and sizeof(int) is 4, for there to be
anywhere from 0 to 16 padding bits, and thus INT_MIN could be anything
from -32767 to -2147483648. Under the same constraints, INT_MAX could
be anything from 32767 to 2147483647.
Thanks Richard for your reply.
So, if the implementation (with int = 4bytes = 32 bits) chose +32767
as the highest value, does that mean all the
values from +32768 to +2147483647 are trap representation
on this implementation ?

Sep 14 '07 #3
ju**********@yahoo.co.in said:

<snip>
So, if the implementation (with int = 4bytes = 32 bits) chose +32767
as the highest value, does that mean all the
values from +32768 to +2147483647 are trap representation
on this implementation ?
Not necessarily, but AIUI it *could* mean that, yes.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 14 '07 #4
On Sep 14, 1:24 pm, "junky_fel...@yahoo.co.in"
<junky_fel...@yahoo.co.inwrote:
Thanks Richard for your reply.
So, if the implementation (with int = 4bytes = 32 bits) chose +32767
as the highest value, does that mean all the
values from +32768 to +2147483647 are trap representation
on this implementation ?
Not quite. The way you described it, you have 16 padding bits. If you
store lets say 32767 into an int value, you will have a sign bit that
is set to zero, fifteen value bits all set to 1, and 16 padding bits
set to some value that the implementation thinks is right. For
example, the padding bits could be all zero, or they could be copies
if the sign bit and the value bits.

By accessing the four bytes of the int using an unsigned char*, you
may be able to figure out which bits are sign bit, value bits and
padding bits (For example, this would work in an implementation where
the padding bits are always zero; if the padding bits are always
copies of other bits, you can't find out which are padding bits). If
you know the padding bits, you could modify padding bits by accessing
the int using an unsigned char*.

The implementation defines what happens: If the implementation says
that there are no trap representations, then storing anything into the
padding bits is legal and doesn't change the value. You store 32767
into an int, change the padding bits any way you like, and the value
in the int is still 32767. On the other hand, the implementation could
say that any setting of the padding bits other than the one it prefers
is a trap representation. Again, store 32767, change the padding bits,
try reading the int, and you get undefined behaviour.

Anyway, the way you wrote it is quite imprecise. You couldn't store a
value of 32768 into an int because there is no such value. You could
say something like "Whenever I store a value from -32768 to 32767, the
representation of the result is the same as on my other computer which
uses a PowerPC processor with INT_MIN/MAX = -2^31, 2^31-1. What
happens if I create a representation that looks like 32768 looks on my
other computer?", but there is no such value as 32768.

Sep 14 '07 #5
"christian.bau" <ch***********@cbau.wanadoo.co.uka écrit dans le message
de news: 11*********************@y42g2000hsy.googlegroups.c om...
On Sep 14, 1:24 pm, "junky_fel...@yahoo.co.in"
<junky_fel...@yahoo.co.inwrote:
>Thanks Richard for your reply.
So, if the implementation (with int = 4bytes = 32 bits) chose +32767
as the highest value, does that mean all the
values from +32768 to +2147483647 are trap representation
on this implementation ?

Not quite. The way you described it, you have 16 padding bits. If you
store lets say 32767 into an int value, you will have a sign bit that
is set to zero, fifteen value bits all set to 1, and 16 padding bits
set to some value that the implementation thinks is right. For
example, the padding bits could be all zero, or they could be copies
if the sign bit and the value bits.

By accessing the four bytes of the int using an unsigned char*, you
may be able to figure out which bits are sign bit, value bits and
padding bits (For example, this would work in an implementation where
the padding bits are always zero; if the padding bits are always
copies of other bits, you can't find out which are padding bits). If
you know the padding bits, you could modify padding bits by accessing
the int using an unsigned char*.

The implementation defines what happens: If the implementation says
that there are no trap representations, then storing anything into the
padding bits is legal and doesn't change the value. You store 32767
into an int, change the padding bits any way you like, and the value
in the int is still 32767. On the other hand, the implementation could
say that any setting of the padding bits other than the one it prefers
is a trap representation. Again, store 32767, change the padding bits,
try reading the int, and you get undefined behaviour.

Anyway, the way you wrote it is quite imprecise. You couldn't store a
value of 32768 into an int because there is no such value. You could
say something like "Whenever I store a value from -32768 to 32767, the
representation of the result is the same as on my other computer which
uses a PowerPC processor with INT_MIN/MAX = -2^31, 2^31-1. What
happens if I create a representation that looks like 32768 looks on my
other computer?", but there is no such value as 32768.
And now let's get practical: can someone share with us an actual encounter
of such things as padding bits and trap values, preferably within this
century ?

--
Chqrlie.
Sep 14 '07 #6
On Sep 14, 11:36 pm, "Charlie Gordon" <n...@chqrlie.orgwrote:
"christian.bau" <christian....@cbau.wanadoo.co.uka écrit dans le message
denews: 1189793897.754500.39__BEGIN_MASK_n#9g02mG7!__...__ **********************@y42g2000hsy.googlegroups.co m...
On Sep 14, 1:24 pm, "junky_fel...@yahoo.co.in"
<junky_fel...@yahoo.co.inwrote:
Thanks Richard for your reply.
So, if the implementation (with int = 4bytes = 32 bits) chose +32767
as the highest value, does that mean all the
values from +32768 to +2147483647 are trap representation
on this implementation ?
Not quite. The way you described it, you have 16 padding bits. If you
store lets say 32767 into an int value, you will have a sign bit that
is set to zero, fifteen value bits all set to 1, and 16 padding bits
set to some value that the implementation thinks is right. For
example, the padding bits could be all zero, or they could be copies
if the sign bit and the value bits.
By accessing the four bytes of the int using an unsigned char*, you
may be able to figure out which bits are sign bit, value bits and
padding bits (For example, this would work in an implementation where
the padding bits are always zero; if the padding bits are always
copies of other bits, you can't find out which are padding bits). If
you know the padding bits, you could modify padding bits by accessing
the int using an unsigned char*.
The implementation defines what happens: If the implementation says
that there are no trap representations, then storing anything into the
padding bits is legal and doesn't change the value. You store 32767
into an int, change the padding bits any way you like, and the value
in the int is still 32767. On the other hand, the implementation could
say that any setting of the padding bits other than the one it prefers
is a trap representation. Again, store 32767, change the padding bits,
try reading the int, and you get undefined behaviour.
Anyway, the way you wrote it is quite imprecise. You couldn't store a
value of 32768 into an int because there is no such value. You could
say something like "Whenever I store a value from -32768 to 32767, the
representation of the result is the same as on my other computer which
uses a PowerPC processor with INT_MIN/MAX = -2^31, 2^31-1. What
happens if I create a representation that looks like 32768 looks on my
other computer?", but there is no such value as 32768.

And now let's get practical: can someone share with us an actual encounter
of such things as padding bits and trap values, preferably within this
century ?
There are some TI processors that support 40 bit integer arithmetic,
using pairs of two 32 bit registers. int = 32 bit, but long = 40 bit
stored in eight bytes. And padding bits in floating-point numbers are
quite common; the compiler that I mostly use has sizeof (long double)
= 16, and long double uses 80 bits.

Sep 15 '07 #7
"christian.bau" <ch***********@cbau.wanadoo.co.ukwrites:
On Sep 14, 11:36 pm, "Charlie Gordon" <n...@chqrlie.orgwrote:
[...]
>And now let's get practical: can someone share with us an actual encounter
of such things as padding bits and trap values, preferably within this
century ?

There are some TI processors that support 40 bit integer arithmetic,
using pairs of two 32 bit registers. int = 32 bit, but long = 40 bit
stored in eight bytes. And padding bits in floating-point numbers are
quite common; the compiler that I mostly use has sizeof (long double)
= 16, and long double uses 80 bits.
Floating-point types don't have "padding bits" in the sense defined in
the standard (beause the standard doesn't specify enough about
floating-point representations for the concept to be necessary).

--
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"
Sep 16 '07 #8

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

Similar topics

3
by: James Marshall | last post by:
I need to detect the type of an object, more than just "object" as typeof gives us. I'm writing a general handler that accepts a variety of objects and properties, and acts accordingly depending...
6
by: Jon Davis | last post by:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current browsers using: <object id="extendedhtml" type="text/html" data="otherpage.html" width="250" height="400"></object> ...
2
by: HairlipDog58 | last post by:
I have a component that implements a property called obj of type object. The intent is that a user can pass in any value or array of values and I will be able to retrieve the values. If the...
2
by: Jon the Blind | last post by:
I'm looking for a way to retrieve data via System.Reflection.FieldInfo.GetValue (which returns an Object) and convert it to XML using XmlConvert.ToString. XmlConvert accepts only specified data...
2
by: Just D. | last post by:
All, Do we have a simple way to Create an object on the fly knowing just an object type? The usual design-time way is to write a code something like this: CObjectType obj = new CObjectType();...
2
by: Alex | last post by:
Dear all I hope you might help me. Here my issue: I am using the following vb.net code to receive members from a windows 2000 active directory group: objecttolook = "group" objlook =...
7
by: Martin Robins | last post by:
I am currently looking to be able to read information from Active Directory into a data warehouse using a C# solution. I have been able to access the active directory, and I have been able to return...
4
by: Scott | last post by:
In order to give a meaning average value and minimum and maximum values, I would like to have a formula for a group of data after taking out those extremes. Can someone share your way to...
3
by: Frank Rizzo | last post by:
I am trying to do some monitoring of some PerfMon counters and have a question. Does PerfMon figure out the Minimum, Maximum, Average values for each counter? Or are those values part of the...
2
by: dh87lfc | last post by:
Hi, I am currently working on a task which requires me to extract the top 10 maximum values from a column in a text file and print them to a new file. I am just wondering what would be the best way...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.