This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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
little reason.

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 ;)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]