J
James Kuyper
Martin wrote:
....
Let me say this frankly: what you say you want to do is pointless, for
precisely the same reason that you can't prevent the optimization. If
there's really a point to what you want to do, you haven't made that
clear. You need to expand your description of the problem to make that
point clear; as soon as you do so, we can tell you what to do to prevent
the optimization.
If you can know for certain that you're checking the same block of
memory that was copied over, before it has had any chance to be changed,
then so can a sufficiently intelligent compiler. If the compiler
recognizes that fact, then it can optimize the memcpy() call away, under
the as-if rule. The only options you have are compiler-specific. You
have to use a compiler that isn't smart enough to recognize this fact,
or you can use a smarter compiler in a mode where such optimizations are
turned off.
....
I stated at the start of this thread why I wanted to avoid optimising
out the memcmp and have restated it since. Please accept that I need
to do so.
Let me say this frankly: what you say you want to do is pointless, for
precisely the same reason that you can't prevent the optimization. If
there's really a point to what you want to do, you haven't made that
clear. You need to expand your description of the problem to make that
point clear; as soon as you do so, we can tell you what to do to prevent
the optimization.
pcmos is not subject to random change between the calls. We are making
it volatile so that we can *pretend* it is subject to random change in
order to prevent the memcmp from being optimised out (although based
on other contributors' posts to this thread that turns out to perhaps
not be a good idea).
If you can know for certain that you're checking the same block of
memory that was copied over, before it has had any chance to be changed,
then so can a sufficiently intelligent compiler. If the compiler
recognizes that fact, then it can optimize the memcpy() call away, under
the as-if rule. The only options you have are compiler-specific. You
have to use a compiler that isn't smart enough to recognize this fact,
or you can use a smarter compiler in a mode where such optimizations are
turned off.