This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Pathalogical divides
- To: kenner at vlsi1 dot ultra dot nyu dot edu (Richard Kenner)
- Subject: Re: Pathalogical divides
- From: Andreas Schwab <schwab at suse dot de>
- Date: Fri, 22 Sep 2000 10:45:18 +0200
- Cc: gcc at gcc dot gnu dot org
- References: <10009211926.AA26210@vlsi1.ultra.nyu.edu>
kenner@vlsi1.ultra.nyu.edu (Richard Kenner) writes:
|> Consider the following program on x86:
|>
|> int rem (int a, int b) { return a % b; }
|>
|> int
|> main ()
|> {
|> printf ("%d\n", rem (0x80000000, -1));;
|> }
|>
|> When run, rather than producing zero, as expected, it gets a SIGFPE.
|> This is because the division of the largest negative integer by negative one
|> results in an overflow.
|>
|> So the first question is whether this is valid C behavior.
IMHO, yes. You are invoking undefined behaviour.
Andreas.
--
Andreas Schwab "And now for something
SuSE Labs completely different."
Andreas.Schwab@suse.de
SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg