use of memset and optimization

Tom Yu tlyu at MIT.EDU
Fri Nov 8 10:50:01 EST 2002


>>>>> "john" == John Hascall <john at iastate.edu> writes:

>> Not only does gcc 3.0.3 not optimize out the memset() call, it also
>> doesn't inline any of the functions.

john>    However, it would be perfectly within its rights to do so,
john>    and perhaps some compiler now or in the future does/will.

I'm not convinced of that.  Consider that an expression statement is a
sequence point.  There is therefore a sequence point between the call
to memset() and the call to free().  If it is possible that a signal
handler might access the value of the object between those two calls,
the standard arguably requires that it be able to see the effects of
the memset().

One could also argue that since the requirement is only for "as if"
behavior in the absence of the volatile qualifier, the implementation
is not required to let the signal handler see the effect of memset()
if the object isn't declared as volatile and there is no visible I/O
that would be affected by such optimization.  In practice, an
implementation would have a difficult time making the determination
that no visible I/O would be affected by optimizing away the call to
memset().

---Tom



More information about the krbdev mailing list