From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30464 invoked by alias); 31 Jul 2014 17:00:58 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 30450 invoked by uid 89); 31 Jul 2014 17:00:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mout.perfora.net Received: from mout.perfora.net (HELO mout.perfora.net) (74.208.4.197) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 31 Jul 2014 17:00:56 +0000 Received: from laplace.local (c-76-103-209-17.hsd1.ca.comcast.net [76.103.209.17]) by mrelay.perfora.net (node=mreueus002) with ESMTP (Nemesis) id 0Lsj4p-1WT1JK3XAH-012L27; Thu, 31 Jul 2014 19:00:53 +0200 Message-ID: <53DA7643.2000004@teli.org> Date: Thu, 31 Jul 2014 17:00:00 -0000 From: Ricardo Telichevesky User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: Compiler warnings, overflow Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2014-07/txt/msg00119.txt.bz2 Hi, hope this is the right list. Here is my code and output, at the bottom of the e-mail. y is "correct", w and z obviously have problems - multiplying two 32-bit integers "hoping" the result would be correct assigning to 64-bit - I guess it is the same problem as double oneThird= 1/3; the result being zero, and not 0.3333. I was wondering if there is any strict warning that would flag the w and z assignments below, or the 1/3 above - the whole right hand side is evaluated as a 32-bit integer number, and assigned to a 64-bit integer or double. Not advocating this should be a default, but turning it on would help me detect some flaws in the code. Took me hours to catch a similar bug in my code, trying to solve a sparse system that has hundreds of millions of variables... Thanks! Ricardo laplace utils % cat ovr.c #include int main() { unsigned int x = 1015625426; unsigned int t = sizeof(double); size_t y = x * sizeof(double); size_t w = x << 3; size_t z = x * t; printf("y= %zd w = %zd z = %zd\n", y, w, z); } laplace utils % gcc -Wall -o ovr ovr.c laplace utils % ovr y= 8125003408 w = 3830036112 z = 3830036112