This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: INT_MIN % -1
- From: Paul Schlie <schlie at comcast dot net>
- To: <gcc at gcc dot gnu dot org>
- Date: Mon, 29 Nov 2004 22:12:06 -0500
- Subject: Re: INT_MIN % -1
> Andreas wrote:
>> terra@gnome.org (Morten Welinder) writes:
>>
>> gcc 3.4 on solaris/sparc seems to get zero; gcc 3.3.1 on linux gives me a
>> crash at runtime. (Because the signed integer division instruction traps
> as documented.)
>
> FWIW, on m68k you'll get -1 (because the divs insn does not modify the
> operands on overflow and doesn't trap either).
Then would guess divs shouldn't be used with operands which may yield
needlessly incorrect results, and would guess it should likely be considered
a code-generator bug if it is; as a compiler which produces code which
may generate needlessly incorrect results (even if misguidedly allowed
by the standard), isn't truly as useful as one which reliably produces
reasonably correct results.
(where I'm assuming: (-INT_MIN / -1) => -1 isn't reasonably correct or
necessary, nor is a run-time exception/trap)
Although possibly naive, I'd like to think that the C standard won't be used
as a crutch, but that GCC may rise above many of the unspecified behaviors,
and establish instead, well defined logically consistent useful ones, which
others may aspire to emulate.