Re: Four problems with Scheme 48 1.8
Michael Sperber <[email protected]>
| Newsgroups | gmane.lisp.scheme.scheme48 |
|---|---|
| Message-ID | <[email protected]> |
Michael Sperber <[email protected]> writes: > Martin Ward <[email protected]> writes: > >> (1) Compiling with gcc version 4.4.0 gives an error on "make test": >> >> FAILURES: >> Test case *3 [misc-big-tests] FAILED: >>>From expression (* 47123 46039) EXPECTED value 2169495797 of 2169495797 >> INSTEAD got -2125471499 >> >> '(#{Check-failure #{Test-case *3} (actual (* 47123 46039) -2125471499) >> (expected 2169495797 2169495797) #{Procedure 983 (equal? in >> scheme-level-1)}}) >> >> Compiling with gcc 4.0.1 seems to work OK. > > This appears to be a bug in gcc 4.4, I'm afraid. Scratch that and substitute "interesting interpretation of the ANSI C standard." The attached patch (which is in the development code) works around the problem. -- Cheers =8-} Mike Friede, Völkerverständigung und überhaupt blabla changeset: 1289:ab92a31cec79 user: Mike Sperber <[email protected]> date: Thu Jul 30 10:40:00 2009 +0200 summary: Work around overflow problem in SMALL_MULTIPLY. diff --git a/c/scheme48vm-prelude.h b/c/scheme48vm-prelude.h --- a/c/scheme48vm-prelude.h +++ b/c/scheme48vm-prelude.h @@ -5,7 +5,15 @@ #include "c-mods.h" #include "scheme48write-barrier.h" -#define SMALL_MULTIPLY(x,y) ((x) * (y)) +/* + * This is to tell the C compiler that the result may be negative even + * though the operands are unsigned. It is still dubious: A cast from + * an unsigned to an int that involves an overflow pretty much has + * undefined result - the C standard does not give us two's complement + * arithmetic. + */ + +#define SMALL_MULTIPLY(x,y) ((long)((unsigned long)(x) * (unsigned long)(y))) #define NO_ERRORS 0 /* extension to errno.h */