459,916 Members | 1,728 Online
Need help? Post your question and get tips & solutions from a community of 459,916 IT Pros & Developers. It's quick & easy.

# minimum and maximum values of an object of type int

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

 P: n/a 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 Email: -www. +rjh@ Google users: "Usenet is a strange place" - dmr 29 July 1999 Sep 14 '07 #2

 P: n/a On Sep 14, 3:31 pm, Richard Heathfield

 P: n/a ju**********@yahoo.co.in said: 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 Email: -www. +rjh@ Google users: "Usenet is a strange place" - dmr 29 July 1999 Sep 14 '07 #4

 P: n/a On Sep 14, 1:24 pm, "junky_fel...@yahoo.co.in"