This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Pathalogical divides


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]