From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17666 invoked by alias); 22 Mar 2012 21:45:52 -0000 Received: (qmail 17642 invoked by uid 22791); 22 Mar 2012 21:45:51 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_JM X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 22 Mar 2012 21:45:38 +0000 From: "jmichae3 at yahoo dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/52661] negative maxint for long long gives warning Date: Thu, 22 Mar 2012 21:54:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jmichae3 at yahoo dot com X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-03/txt/msg01979.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661 --- Comment #14 from Jim Michaels 2012-03-22 21:45:33 UTC --- OK, given your argument, let's look at -32768 for a short. it's just too big because 32768 is larger than the size of an int, so it's considered unsigned, right? wrong. no warning message. which is what I have been trying to say. your argument doesn't hold water. this value is within the proper size for an int. it's the minimum number of an int. -32768 is the one value that is valid which doesn't fit most people's use of an int, which is only the range -32767..32767. that is NOT the full range of a short. I am not sure why you are rooting for the compiler's way of doing things, it's broken. I understand what you are saying, I also understand that assuming the value is unsigned because it's on the edge is wrong. how about an if statement, like if (-1==sign && 9223372036854775808==mantissa) { datum=mantissa*sign; } else if (1==sign && 9223372036854775808==mantissa) { datum=mantissa; } else if (-1==sign && mantissa > 9223372036854775808) { printf("error:....\n"); } else if (1==sign && mantissa > 9223372036854775808) { printf("error:....\n"); } why not just use an unsigned long long to hold the mantissa and keep the sign as a bool or store it as another number as +1 or -1, and do some sort of range check to make sure the number input is valid? there are multiple ways