Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Even more problems with lcc-win Date: Wed, 29 Mar 2017 16:58:04 -0700 Organization: None to speak of Lines: 97 Message-ID: References: <9fdaf805-d21a-49f3-ab54-4fa17b91f731@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="ba8d8263898e17bc1d1fa2c116c9e248"; logging-data="17156"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fl0kjeBoh3gnSAzs3Bwn9" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:AYFBt1PHvgFAcTJkT2DZ7HG1pps= sha1:IWH3EjcgytExbRNVDsk4i3W5qRc= Xref: csiph.com comp.lang.c:107443 mertesthomas@gmail.com writes: > Am Mittwoch, 29. März 2017 21:22:12 UTC+2 schrieb Keith Thompson: >> mertesthomas writes: >> [...] >> > - Tcc: Compiles, but integer divisions with maximum values >> > are not correct (see tcc_err2.c). >> [...] >> > ========== begin tcc_err2.c ========== >> > #include "stdio.h" >> > >> > #if ULONG_MAX > 4294967295U >> > typedef long intType; >> > #define INT_SUFFIX(num) num ## L >> > #define SUFFIX "L" >> > #define INTTYPE_FORMAT "l" >> > #define MESSAGE "Using long.\n" >> > #else >> > typedef long long intType; >> > #define INT_SUFFIX(num) num ## LL >> > #define SUFFIX "LL" >> > #define INTTYPE_FORMAT "ll" >> > #define MESSAGE "Using long long.\n" >> > #endif >> > >> > #define F_D(width) "%" #width INTTYPE_FORMAT "d" >> > >> > #if 0 >> > /* Allow the compiler to compute the division. */ >> > #define intExpr(num) (num) >> > #else >> > /* The division will (probably) be done at runtime. */ >> > intType intExpr (intType number) { return number; } >> > #endif >> > >> > >> > int main (int argc, char **argv) >> > { >> > printf("sizeof(long): %lu\n", sizeof(long)); >> > printf("sizeof(long long): %lu\n", sizeof(long long)); >> > printf(MESSAGE); >> > printf("-9223372036854775808" SUFFIX " / -2147483649" SUFFIX " = " F_D(20) " expected: 4294967294\n", >> > intExpr(INT_SUFFIX(-9223372036854775807)-1) / INT_SUFFIX(-2147483649)); >> > printf("-9223372036854775808" SUFFIX " / -2147483648" SUFFIX " = " F_D(20) " expected: 4294967296\n", >> > intExpr(INT_SUFFIX(-9223372036854775807)-1) / INT_SUFFIX(-2147483648)); >> > printf(" 9223372036854775807" SUFFIX " / -2147483649" SUFFIX " = " F_D(20) " expected: -4294967294\n", >> > intExpr(INT_SUFFIX( 9223372036854775807)) / INT_SUFFIX(-2147483649)); >> > printf(" 9223372036854775807" SUFFIX " / -2147483648" SUFFIX " = " F_D(20) " expected: -4294967295\n", >> > intExpr(INT_SUFFIX( 9223372036854775807)) / INT_SUFFIX(-2147483648)); >> > printf("-9223372036854775808" SUFFIX " %% -2147483649" SUFFIX " = " F_D(20) " expected: -2\n", >> > intExpr(INT_SUFFIX(-9223372036854775807)-1) % INT_SUFFIX(-2147483649)); >> > printf("-9223372036854775808" SUFFIX " %% -2147483648" SUFFIX " = " F_D(20) " expected: 0\n", >> > intExpr(INT_SUFFIX(-9223372036854775807)-1) % INT_SUFFIX(-2147483648)); >> > printf(" 9223372036854775807" SUFFIX " %% -2147483649" SUFFIX " = " F_D(20) " expected: 1\n", >> > intExpr(INT_SUFFIX( 9223372036854775807)) % INT_SUFFIX(-2147483649)); >> > printf(" 9223372036854775807" SUFFIX " %% -2147483648" SUFFIX " = " F_D(20) " expected: 2147483647\n", >> > intExpr(INT_SUFFIX( 9223372036854775807)) % INT_SUFFIX(-2147483648)); >> > return 0; >> > } >> > ========== end tcc_err2.c ========== >> >> I compiled and ran your program using tcc, and it appeared to pass. >> I'm using tcc 0.9.26 on x86_64 Linux (Ubuntu 16.10). > > Ok. I use tcc 0.9.25 and running tcc_err2 under Linux gives: > > sizeof(long): 8 > sizeof(long long): 8 > Using long long. > -9223372036854775808LL / -2147483649LL = 0 expected: 4294967294 > -9223372036854775808LL / -2147483648LL = 0 expected: 4294967296 > 9223372036854775807LL / -2147483649LL = 0 expected: -4294967294 > 9223372036854775807LL / -2147483648LL = 0 expected: -4294967295 > -9223372036854775808LL % -2147483649LL = -9223372036854775808 expected: -2 > -9223372036854775808LL % -2147483648LL = -9223372036854775808 expected: 0 > 9223372036854775807LL % -2147483649LL = 9223372036854775807 expected: 1 > 9223372036854775807LL % -2147483648LL = 9223372036854775807 expected: 2147483647 > >> It would be handy if it would explicitly report an error if a value >> doesn't match. > > Maybe I already reported the error. :-) > It is some time ago when I wrote tcc_err2.c and I cannot remember > what I did with it. What I meant, in case it wasn't clear, is that the program should print a PASS/FAIL result, either a summary or for each sub-test, rather than requiring the reader to visually compare the actual vs. the expected value. > I will look for tcc 0.9.26 and do the tests again. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"