Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
To: axp-list@redhat.com
Subject: Re: is this feature documented?
Date: 03 Dec 2002 08:36:02 +0100	[thread overview]
Message-ID: <87n0nn3671.fsf@student.uni-tuebingen.de> (raw)
In-Reply-To: <Pine.LNX.4.44.0212021828310.26163-100000@res104a-017.rh.rit.edu>

"Andrew A. Gill" <superluser@mail.isc.rit.edu> writes:

> 	[superluser@trystero superluser]$ cat fpe.cc 
> 	#include <stdio.h>
> 
> 	    int main(void)
> 	    {
> 	      int x = (int) (4/(float)0);
> 	      printf ("x = %i\n", x);
> 	    }
> 
> 	[superluser@trystero superluser]$ g++ fpe.cc 
> 	fpe.cc: In function `int main()':
> 	fpe.cc:5: warning: division by zero in `4 / 0.'
> 	[superluser@trystero superluser]$ ./a.out 
> 	x = 0
> 
> This is gcc version 3.2 20021115 (Red Hat Linux 8.0 3.2-14).  Should
> this be normal behavior?  Is this the expected output of standard
> C++?

It is correct. 4.9: "The behavior is undefined if the truncated value
cannot be represented in the destination type." So returning 0 is
correct, as would be returning 23, crashing, or formatting the hard
disk.

It is probably not what one would expect, though; usually on Alpha,
doing calculations with magic values like NAN raises a signal. It only
doesn't happen here because the compiler does constant folding on it.

BTW, with g++ 3.3 (CVS) you get -1, and with cxx a floating point
exception.

-- 
	Falk




      parent reply	other threads:[~2002-12-03  7:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-02 23:36 is this feature documented? Andrew A. Gill
2002-12-03  0:08 ` Kelledin
2002-12-03  8:20   ` Andrew A. Gill
2002-12-03  7:36 ` Falk Hueffner [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox