Pathalogical divides

Andreas Schwab schwab@suse.de
Fri Sep 22 01:45:00 GMT 2000


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


More information about the Gcc mailing list