Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ? 
Author Message
 Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ?

Hi there,

Am quite new to this news group ..
A question troubled my mind this afternoon and is as follows ..

In limits.h, we got INT_MIN,LONG_MIN etc., but we dont have any such
minimum limits for any Unsigned DataTypes like what we could have as
UINT_MIN, ULONG_MIN , but not in reality ..

I understand that it does'nt matter for storing an unsigned int i = -1,
though some compilers gives out a warning and it all matters in
manipulation of i.

i=-1 still corresponds to some value like 4294967295, which is UINT_MAX.

But we do have INT_MAX which is 2147483647. Even if you assign
4294967295 for a signed integer, it would very well take this as -1.
Still we have 2147483647 as INT_MAX.

If we think in a similar way, why dont we have UINT_MIN as 0 and
ULONG_MIN as 0, though it all matters the way compiler manipulates with
the integer like what we have in INT_MAX, INT_MIN.

I guess my question is quite confusing(which does so to me) and
abstract, but still i find something is flashing out of it ...????!!!

Anyway if any of you could please answer my query, that could be more
helpfull to me.

Cheers
Balaji

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Fri, 04 Apr 2003 03:00:00 GMT  
 Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ?

Quote:

> If we think in a similar way, why dont we have UINT_MIN as 0 and
> ULONG_MIN as 0, though it all matters the way compiler manipulates with
> the integer like what we have in INT_MAX, INT_MIN.

Well, I think here you have the solution: U<whatever>_MIN is _always_ 0;
that's how unsigned types are defined. There is, therefore, no need for
these identifiers.

Richard



Fri, 04 Apr 2003 03:00:00 GMT  
 Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ?

Because the answer is always going to be 0 for any unsigned integer
or character.



Fri, 04 Apr 2003 03:00:00 GMT  
 Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ?

Quote:

>Hi there,

>Am quite new to this news group ..
>A question troubled my mind this afternoon and is as follows ..

>In limits.h, we got INT_MIN,LONG_MIN etc., but we dont have any such
>minimum limits for any Unsigned DataTypes like what we could have as
>UINT_MIN, ULONG_MIN , but not in reality ..

The minimum value of an unsigned integer is always zero so there's no
point in providing specific defines for it.

Quote:
>I understand that it does'nt matter for storing an unsigned int i = -1,
>though some compilers gives out a warning and it all matters in
>manipulation of i.

>i=-1 still corresponds to some value like 4294967295, which is UINT_MAX.

It is guaranteed to store UINT_MAX in i.

Quote:
>But we do have INT_MAX which is 2147483647. Even if you assign
>4294967295 for a signed integer, it would very well take this as -1.

If you try to convert a value to a signed integer type that that type
cannot represent then you get undefined behaviour, your program might
crash. In other words this is something that you must make sure that
your program never does. Conversions of out of range values to unsigned
integers are however well-defined. The result is a reduction of
the value modulo one greater than the maximum value that the undigned type
can represent.

Quote:
>Still we have 2147483647 as INT_MAX.

>If we think in a similar way, why dont we have UINT_MIN as 0 and
>ULONG_MIN as 0, though it all matters the way compiler manipulates with
>the integer like what we have in INT_MAX, INT_MIN.

These don't tell us anything that we don't already know. UINT_MAX, INT_MIN
etc.  can very between compilers, UINT_MIN etc. could not.

--
-----------------------------------------


-----------------------------------------



Sat, 05 Apr 2003 03:00:00 GMT  
 Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ?

Quote:


>>I understand that it does'nt matter for storing an unsigned int i = -1,
>>though some compilers gives out a warning and it all matters in
>>manipulation of i.

>>i=-1 still corresponds to some value like 4294967295, which is UINT_MAX.

>It is guaranteed to store UINT_MAX in i.

Out of interest, is that in the standard? After all, there are some
very strange systems out in the real world where 1s complement is
used. Admittedly I don't know if these systems have C compilers, but
it is possible.

Quote:
>>But we do have INT_MAX which is 2147483647. Even if you assign
>>4294967295 for a signed integer, it would very well take this as -1.

>If you try to convert a value to a signed integer type that that type
>cannot represent then you get undefined behaviour, your program might
>crash. In other words this is something that you must make sure that
>your program never does. Conversions of out of range values to unsigned
>integers are however well-defined. The result is a reduction of
>the value modulo one greater than the maximum value that the undigned type
>can represent.

I did not think that this was guaranteed.
--
Mark Gordon
Dyslexic C Programmer,
At least the compiler ensures I spell variable names consistently wrong.
For a faster email response replace orange.net with causeway-tech.com


Sat, 05 Apr 2003 03:00:00 GMT  
 Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ?

Quote:

>>But we do have INT_MAX which is 2147483647. Even if you assign
>>4294967295 for a signed integer, it would very well take this as -1.

>If you try to convert a value to a signed integer type that that type
>cannot represent then you get undefined behaviour, your program might
>crash.

Nope.  The result of such a conversion is implementation-defined.  Your
program cannot crash because of this.

Dan
--
Dan Pop
CERN, IT Division

Mail:  CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland



Sat, 05 Apr 2003 03:00:00 GMT  
 Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ?
On Tue, 17 Oct 2000 15:41:48 +0100, Mark Gordon

Quote:




>>>I understand that it does'nt matter for storing an unsigned int i = -1,
>>>though some compilers gives out a warning and it all matters in
>>>manipulation of i.

>>>i=-1 still corresponds to some value like 4294967295, which is UINT_MAX.

>>It is guaranteed to store UINT_MAX in i.

>Out of interest, is that in the standard? After all, there are some
>very strange systems out in the real world where 1s complement is
>used. Admittedly I don't know if these systems have C compilers, but
>it is possible.

Yes, assigning -1 to an unsigned int object is guaranteed to
store UINT_MAX in that object.  This is a requirement of the
standard, unrelated to the bitwise representation of signed or
unsigned integers.

...

Quote:
>> Conversions of out of range values to unsigned
>>integers are however well-defined. The result is a reduction of
>>the value modulo one greater than the maximum value that the undigned type
>>can represent.

>I did not think that this was guaranteed.

It's in the second and third paragraphs of 6.2.1.2 in the C90
standard, but instead of "modulo" the standard says "the
nonnegative remainder on division by the number one greater than
the largest unsigned number that can be represented in the type".

--

Lucent Technologies Software Products Group



Sat, 05 Apr 2003 03:00:00 GMT  
 Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ?

Quote:



>>>I understand that it does'nt matter for storing an unsigned int i = -1,
>>>though some compilers gives out a warning and it all matters in
>>>manipulation of i.

>>>i=-1 still corresponds to some value like 4294967295, which is UINT_MAX.

>>It is guaranteed to store UINT_MAX in i.

>Out of interest, is that in the standard?

Yup.

Quote:
>After all, there are some
>very strange systems out in the real world where 1s complement is
>used. Admittedly I don't know if these systems have C compilers, but
>it is possible.

Some of them have.  1's complement is relevant to *signed* arithmetic
*only*.  Unsigned arithmetic is performing using a pure binary
representation.

Quote:
>>>But we do have INT_MAX which is 2147483647. Even if you assign
>>>4294967295 for a signed integer, it would very well take this as -1.

>>If you try to convert a value to a signed integer type that that type
>>cannot represent then you get undefined behaviour, your program might
>>crash. In other words this is something that you must make sure that
>>your program never does. Conversions of out of range values to unsigned
>>integers are however well-defined. The result is a reduction of
>>the value modulo one greater than the maximum value that the undigned type
>>can represent.

>I did not think that this was guaranteed.

Regardless of what you thought (or may be still thinking) the standard
says:

    When a signed integer is converted to an unsigned integer with
    equal or greater size, if the value of the signed integer is
    nonnegative, its value is unchanged.  Otherwise: if the unsigned
    integer has greater size, the signed integer is first promoted to the
    signed integer corresponding to the unsigned integer; the value is
    converted to unsigned by adding to it one greater than the largest
    number that can be represented in the unsigned integer type.

Does this match Lawrence's text above?

Dan
--
Dan Pop
CERN, IT Division

Mail:  CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland



Sat, 05 Apr 2003 03:00:00 GMT  
 Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ?

Quote:


> writes:


>>>But we do have INT_MAX which is 2147483647. Even if you assign
>>>4294967295 for a signed integer, it would very well take this as -1.

>>If you try to convert a value to a signed integer type that that type
>>cannot represent then you get undefined behaviour, your program might
>>crash.

>Nope.  The result of such a conversion is implementation-defined.  Your
>program cannot crash because of this.

You're right that it isn't undefined (I don't know how many times I must
have said that). However C99 has thrown a spanner in the works: it allows
as an alternative to an implementation-defined value an implementation-
defined signal to be raised. So in C99 the program can in a specific
sense crash.

--
-----------------------------------------


-----------------------------------------



Sat, 05 Apr 2003 03:00:00 GMT  
 Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ?

Quote:



>>>Conversions of out of range values to unsigned
>>>integers are however well-defined. The result is a reduction of
>>>the value modulo one greater than the maximum value that the undigned type
>>>can represent.

...

Quote:
>Regardless of what you thought (or may be still thinking) the standard
>says:

>    When a signed integer is converted to an unsigned integer with
>    equal or greater size, if the value of the signed integer is
>    nonnegative, its value is unchanged.  Otherwise: if the unsigned
>    integer has greater size, the signed integer is first promoted to the
>    signed integer corresponding to the unsigned integer; the value is
>    converted to unsigned by adding to it one greater than the largest
>    number that can be represented in the unsigned integer type.

>Does this match Lawrence's text above?

My text also covers the case when converting to a narrower unsigned type.

--
-----------------------------------------


-----------------------------------------



Sat, 05 Apr 2003 03:00:00 GMT  
 Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ?

Quote:


>>Regardless of what you thought (or may be still thinking) the standard
>>says:

I'm quite willing to be educated, so I have now added this to my store
of knowledge. If I was not willing to be told I was wrong, I would not
have asked :-)

Thank you for your responses.
--
Mark Gordon
Dyslexic C Programmer,
At least the compiler ensures I spell variable names consistently wrong.
For a faster email response replace orange.net with causeway-tech.com



Sun, 06 Apr 2003 03:00:00 GMT  
 Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ?


Quote:



>>>Regardless of what you thought (or may be still thinking) the standard
>>>says:

>I'm quite willing to be educated, so I have now added this to my store
>of knowledge. If I was not willing to be told I was wrong, I would not
>have asked :-)

>Thank you for your responses.

Be careful about t{*filter*} your followups. You left an attribution to me
at the top, but nothing you quoted was written by me.

--
-----------------------------------------


-----------------------------------------



Sun, 06 Apr 2003 03:00:00 GMT  
 Why not the minimum value for Unsigned datatypes not declared (for example UINT_MIN or ULONG_MIN) in limits.h ?


Quote:
>Hi there,

>Am quite new to this news group ..
>A question troubled my mind this afternoon and is as follows ..

>In limits.h, we got INT_MIN,LONG_MIN etc., but we dont have any such
>minimum limits for any Unsigned DataTypes like what we could have as
>UINT_MIN, ULONG_MIN , but not in reality ..

Come on. What is the minimum value for any unsigned integer?

--
-hs-    Tabs out, spaces in.
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkum.com/htm_cl
FAQ de FCLC : http://www.isty-info.uvsq.fr/~rumeau/fclc



Mon, 07 Apr 2003 07:04:57 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Why unsigned chars not default?

2. BOOL: why int and not unsigned char ?

3. Not All Control Paths Return A Value/ Everything Is Not Valid

4. Usage of uint not widespread

5. CFile not working properly, can't figure out why (last message not sent properly)

6. ImageButton Click Event Handler Not Getting Fired, why not

7. Only Datatype required - not variable name

8. UINT, LONG vs. unsigned, long

9. Are unsigned types not CLS compliant?

10. types.h:193: declaration does not declare anything

11. Struct NOT declared...

12. optional args not declared as VARIANT

 

 
Powered by phpBB® Forum Software