Martin Pitt <mpitt@debian.org> writes:
> The C99 standard [2], section 6.5.5 paragraph 5 actually says:
> "The result of the / operator is the quotient from the division of
> the first operand by the second; the result of the % operator is the
> remainder. In both operations, if the value of the second operand is
> zero, the behavior is undefined."
> so the gcc folk's claim that this isn't a gcc bug looks justified.
The gcc guys are full of it. The issue that is relevant here is the C
standard's definition of sequence points, and in particular the
requirement that visible side effects of a later statement cannot happen
before the execution of an earlier function call. The last time I
pestered them about this, I got some lame claim that a SIGFPE wasn't a
side effect within the definitions of the spec. At that point useful
discussion stopped, because it's impossible to negotiate with someone
who's willing to claim that.
> Aurelien sent a straightforward patch for this, I updated it to apply
> to current git head, updated the comments, and git-formatted it.
Hmm ... I'm willing to put in the extra return statements, but not to
remove the comments that we're working around a gcc bug. In particular,
given the gcc folks' claim that they need not consider the timing of
program-generated signals, there is really nothing to stop them from
trying to push the division up before the return too. This is nothing
but a band-aid for a non-standards-compliant optimizer.
regards, tom lane