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 12:22:04 -0700 Organization: None to speak of Lines: 70 Message-ID: References: <9fdaf805-d21a-49f3-ab54-4fa17b91f731@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="87ae93983dfe9544538d09400a3dd74d"; logging-data="17156"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fAFJWN2Cmh5iQte8IRYGN" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:TXhc/Y2GI0ITDXbHD/LGWMAxBUA= sha1:jl2/VeVGRsos6CtVTKoqQMgJBpg= Xref: csiph.com comp.lang.c:107413 mertesthomas@gmail.com 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). It would be handy if it would explicitly report an error if a value doesn't match. Also, the correct format for size_t is "%zu", not "%lu". -- 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"