*BSD News Article 13947


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!decwrl!decwrl!sun-barr!rutgers!njitgw.njit.edu!hertz.njit.edu!kxn3796
From: kxn3796@hertz.njit.edu (Ken Nakata CIS stnt)
Newsgroups: comp.os.386bsd.bugs
Subject: Re: gcc 2.3.3 bug?
Message-ID: <1993Apr3.032136.2935@njitgw.njit.edu>
Date: 3 Apr 93 03:21:36 GMT
References: <1p7c3mINNdh5@urmel.informatik.rwth-aachen.de> <1993Mar30.092201.1099@runx.oz.au>
Sender: news@njit.edu
Organization: New Jersey Institute of Technology, Newark, N.J.
Lines: 49
Nntp-Posting-Host: hertz.njit.edu

In article <1993Mar30.092201.1099@runx.oz.au> you write:
>In article <1p7c3mINNdh5@urmel.informatik.rwth-aachen.de> kuku@acds.physik.rwth-aachen.de writes:
>>
>>Sure, I believe this is not a bug. Instead it might have creeped in 
>>by the various patches I applied to gcc in the context of float.h and libm.
>>...
>>#include <limits.h>
>>
>>int i = -2147483648;
>>
>>main() {
>>  
>>   printf("%d %d\n",INT_MIN,i);
>>}
>>
>>My gcc2.3.3 issues a warning: integer constant so large that it is unsigned.
>>Obviously it is in the range of INT_MIN and INT_MAX. 
>
>The warning is correct.  The constant in the initialization of `i' is
>unsigned and 1 larger than INT_MAX.  It would be the same without the
 ^^^^^^^^
I don't understand this.  Could you explain why *unsigned* is applied?

>`-' sign.  When it is assigned to `i', overflow occurs and the result is
>undefined.  On 2's complement 32-bit machines like the i386, the result
>is usually what you want.
>
>INT_MIN is carefully defined as (-0x7fffffff-1) in <limits.h> so that it
>is not unsigned and so that the negation doesn't cause overflow.  It
>should be equally carefully defined in the gcc <limits.h> as something
>like (-INT_MAX-1).
>-- 
>Bruce Evans  bde@runx.oz.au

If the scanner evaluates "2147483648" at first and then it takes negative
value with '-', I can understand.  It's likely that the warning is produced
when the scanner evaluates an unsigned value 2147483648.  Is this correct?
But even if this is correct, it seems to me that this depends on the
compiler's implementation.  I wonder whether or not there are more
sophisticated explanations...

Thanks in advance.

Ken Nakata
-- 
/* I apologize if there are incorrect, rude, and/or impolite expressions in
this mail or post. They are not intended. Please consider that English is a
second language for me and I don't have full understanding of certain words
or each nuance of a phrase.  Thank you. -- Ken Nakata, CIS student, NJIT */