This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug other/23572] No warning for assigning a value to a 'float' variable that overflows with option -Wextra
- From: "qiyaoltc at cn dot ibm dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 Aug 2005 02:57:47 -0000
- Subject: [Bug other/23572] No warning for assigning a value to a 'float' variable that overflows with option -Wextra
- References: <20050826075201.23572.qiyaoltc@cn.ibm.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From qiyaoltc at cn dot ibm dot com 2005-08-29 02:57 -------
OK.
GCC version: 3.4.3 20050227 (Red Hat 3.4.3-22.1)
GNU C Library: stable release version 2.3.4
OS : Red Hat Enterprise Linux AS release 4 (Nahant Update 1)
I write a small example named overflow-test.c, here is the source code:
1 #include<stdio.h>
2 int main()
3 {
4 /* overflow. */
5 float f1 = 3.5E+38;
6 /* underflow. */
7 float f2 = 3.3E-46;
8 /* overflow. */
9 double d1 = 1.9E+308;
10 /* underflow. */
11 double d2 = 1.4E-325;
12 /* overflow, 2**32. */
13 int i = 4294967296;
14
15 printf("%e,%e,%e,%e\n",f1,f2,d1,d2);
16 printf("%d\n",i);
17 return 0;
18 }
And I compile it like this:
[qiyao@patch]$ gcc -o overflow-test -Wextra -Wall -g overflow-test.c
overflow-test.c: In function `main':
overflow-test.c:13: warning: integer constant is too large for "long" type
overflow-test.c:13: warning: overflow in implicit constant conversion
I run it,
[qiyao@patch]$ ./overflow-test
inf,0.000000e+00,inf,0.000000e+00
0
I hope this example would be helpful. Any comments are highly aprreciated!
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23572