From: Derek M Jones <derek@knosof.co.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Al Viro <viro@ftp.linux.org.uk>,
Neil Booth <neil@daikokuya.co.uk>,
Josh Triplett <josh@freedesktop.org>,
linux-sparse@vger.kernel.org
Subject: Re: fun with ?:
Date: Thu, 24 May 2007 00:29:43 +0100 [thread overview]
Message-ID: <4654CE67.9070106@knosof.co.uk> (raw)
In-Reply-To: <alpine.LFD.0.98.0705231456330.3890@woody.linux-foundation.org>
Linus,
>>> passes with -pedantic -std=c99. Replacing that with 1 + n - n + n - n
>>> is still OK with gcc; 1 + n + n - n - n is not.
>>>
>>> So that's hardly an example of, well, anything.
>> It is an example of order of evaluation mattering when overflow
>> occurs.
>
> No it isn't.
It was intended as a probabilit statement (ok, I did not make that
clear). An expression containing n+n is more likely to overflow
than one containing n-n.
Anyway, getting away from nit-picking of what was intended to be a throw
away remark.
> "1 + n - n" can overflow equally as "1 + n + n - n -n" can, and if you
> want them to do saturation or something, you cannot optimize _either_ of
> them to just "1". If "n" is MAX_INT, then with saturating arithmetic,
> neither of them results in 1.
Saturated arithmetic kills off so many optimizations because reordering
an expression might produce different results.
> Not that signed overflow is even specified by the C standard (and
> unsigned is specified to be well-behaved).
Overflow for signed integer types is undefined behavior
(well technically this is an instance of
"... not in the range of representable values for its type",
sentence 490 http://c0x.coding-guidelines.com/6.5.html).
> So it seems to be purely a compiler misfeature. No excuses.
This is the point of the discussion that has got me confused.
What compiler misfeature? Perhaps I am using the 'wrong' version
of gcc (version 4.0.2), but I get the expected wrapping behavior (ie,
the compiler tries to behave at translate time the same way as st
runtime).
--
Derek M. Jones tel: +44 (0) 1252 520 667
Knowledge Software Ltd mailto:derek@knosof.co.uk
Applications Standards Conformance Testing http://www.knosof.co.uk
next prev parent reply other threads:[~2007-05-23 23:29 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-19 2:52 fun with ?: Al Viro
2007-05-22 21:40 ` Josh Triplett
2007-05-22 22:46 ` Al Viro
2007-05-22 23:24 ` Josh Triplett
2007-05-23 0:02 ` Al Viro
2007-05-23 0:25 ` Al Viro
2007-05-23 1:05 ` Josh Triplett
2007-05-23 4:53 ` Al Viro
2007-05-23 12:26 ` Morten Welinder
2007-05-23 1:03 ` Josh Triplett
2007-06-03 1:05 ` Al Viro
2007-05-23 14:25 ` Neil Booth
2007-05-23 14:32 ` Al Viro
2007-05-23 14:47 ` Neil Booth
2007-05-23 15:32 ` Al Viro
2007-05-23 23:01 ` Neil Booth
2007-05-24 0:10 ` Derek M Jones
2007-05-24 0:14 ` Al Viro
2007-05-23 21:16 ` Derek M Jones
2007-05-23 21:59 ` Linus Torvalds
2007-05-23 23:29 ` Derek M Jones [this message]
2007-05-24 0:02 ` Al Viro
2007-05-24 0:29 ` Linus Torvalds
2007-05-24 1:36 ` Brett Nash
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4654CE67.9070106@knosof.co.uk \
--to=derek@knosof.co.uk \
--cc=josh@freedesktop.org \
--cc=linux-sparse@vger.kernel.org \
--cc=neil@daikokuya.co.uk \
--cc=torvalds@linux-foundation.org \
--cc=viro@ftp.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.