Path: utzoo!attcan!uunet!munnari.oz.au!metro!ipso!runxtsa!edward From: edward@runxtsa.runx.oz.au (Edward Birch) Newsgroups: comp.lang.c++ Subject: MININT problem with C++ streams Keywords: c++,C++,MININT,streams Message-ID: <1959@runxtsa.runx.oz.au> Date: 12 Jul 90 01:32:32 GMT Organization: RUNX Unix Timeshare. Sydney, Australia. Lines: 48 MININT is not printed out correctly by some Glockenspiel and AT&T C++ compilers. The below program produced the following output: assuming 2's complement arithmatic & sizeof(long) = 4 & 8 bits per byte then using `C' we get MININT = 80000000 or -2147483648 and using C++ we get = 80000000 or -( ------------------------------------------------------------------------ #include main() { long x = 0x80000000; /* minint, -2147483648 */ printf("assuming 2's complement arithmatic &\n"); printf(" sizeof(long) = 4 & 8 bits per byte\n"); printf("\n"); printf("then using `C' we get MININT = %08lx or %ld\n", x, x); cout << "and using C++ we get = " << hex(x, 8); cout << " or " << x << "\n"; return 0; // exit(0); } ------------------------------------------------------------------------ I think the bug is caused by an assumption in the C++ library going something like: if (v < 0) { emit_char('-'); v = -v; // clearly wrong when v = MININT with // (2's complement arithmatic) } ------------------------------------------------------------------------ Edward Birch Phone: (02) 958-2119 UUCP: seismo!munnari!runx.oz!edward ACSnet: edward@runx.oz ARPA: edward%runx.oz@seismo.css.gov CSNET: edward@runx.oz