On 02/05/2017 09:10 PM, Kang-Che Sung wrote: > On Mon, Feb 6, 2017 at 8:52 AM, Rob Landley <[email protected]> wrote: >> What's an archive input that actually fails? What's an example of a >> processor machine language that doesn't produce 0x80000000 for 1<<31? >> >> Where does this actually cause a problem? > > I think at least this silences a "undefined behavior" warning, and that's > enough for the patch.
So the problem _is_ the warning? There's no real issue, just a noisy compiler? > Sure, many CPU architectures out there use two's > complement, but that's not mandated in the C standard. Which is why we have more than one standard: Posix, LP64, LSB, ELF... Posix requires a machine to handle two's complement here: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdint.h.html Could you give me an example of an architecture from this century that _doesn't_ use two's complement? The IBM S/360 (introduced in 1964) used two's complement. The first minicomputer (PDP-8 in 1965) used two's complement. The first microcomputer (Altair, 1975) used two's complement (altair basic manual page 28 says so)... Setting aside the fact that a one's complement machine, which was the big historical competitor to two's complement binary representation of negative numbers, would _also_ know that 0x40000000 left shifted one place becomes 0x80000000 and would just do different things with that number if you then tried to add or subtract the result, but should handle boolean algebra just fine. My question is "do any still exist, let alone have a c99 compiler"? Even the _historical_ one's complement machines I can find that straggled into the 1980's (like the CDC Cyber-18) used a 6 bit word, not an 8 bit word. (Which puts them in violation of C99 section 5.2.4.2.1.) Here's this question coming up 9 years ago where people found some checksum formats using it, but no processor ALU doing math in anything but two's complement: http://stackoverflow.com/questions/161797/is-ones-complement-a-real-world-issue-or-just-a-historical-one That links to people asking the same question on usenet's C group in 1993 and nobody back then (25 years ago) could come up with an example still in use: https://groups.google.com/forum/#!topic/comp.std.c/GlZeSxBnCW0 Do you know something they don't? What's an example of a machine built in the last 30 years that _doesn't_ use two's complement? Rob P.S. Yes I'm aware of https://en.wikipedia.org/wiki/Ternary_computer but A) Setun-70 was more than 40 years ago in Russia and they only made a couple, B) if you're going there please explain how bit-shift operators would work in that environment at all. P.P.S. Yes I once wrote assembly for a "binary coded decimal" machine back in college, but they had normal binary math modes too (bcd was more or less like floating point, you used it for certain _kinds_ of calculations but it's generally not what your for loop iterated on) and if you're going there please explain how bit shifting happens at all using bcd instructions or how 30 vs 31 bits would have significance in that context? If there _was_ a problem on such a machine, how would typecasting to unsigned fix it? _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
