This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] C undefined behavior fix
- From: Linus Torvalds <torvalds at transmeta dot com>
- To: mike stump <mrs at windriver dot com>
- Cc: <dennis at juniper dot net>, <rth at redhat dot com>, <gcc at gcc dot gnu dot org>, <paulus at samba dot org>
- Date: Sat, 5 Jan 2002 20:54:57 -0800 (PST)
- Subject: Re: [PATCH] C undefined behavior fix
On Sat, 5 Jan 2002, mike stump wrote:
> and notice that the compiler does the right thing. Try it without the
> call to foo, and watch it do the wrong thing.
This is by no mans guaranteed by the standard either, and I don't think
gcc really guarantees it either.
Traditionally "volatile" has only had an impact on _accesses_, not on
pointer arithmetic. And if you cast to volatile only to cast back to
non-volatile, I suspect that the behaviour will be different on different
versions of gcc.
I tried the "cast to volatile and back", and it has no impact on code
generation for me when done as a straightforward macro, while it generated
truly horrible code when done in an inline function.
In short, I think you're not really showing off any gcc feature, you're
showing off a random effect of the fact that many gcc optimizations throw
up their hands in surrender when they see "volatile". Often with very
But it is definitely _not_ a feature you can depend on (I bet you noticed
this, and that you also noticed that when you tried to use a straight
macro your example just didn't work ;)