use of memset and optimization
raeburn at MIT.EDU
Fri Nov 8 21:01:00 EST 2002
Tom Yu <tlyu at MIT.EDU> writes:
> You would probably have to implement a memset() surrogate that takes a
> pointer to volatile as input. Wrapping memset() with a function that
> takes a pointer to volatile is undefined, since by calling memset()
> you are discarding the qualifier from the pointed-to type.
For a solution that'll work in most cases, create a separate function
to do a memset; gcc won't expand it inline (and possibly eliminate it)
unless a call occurs later in the same source file. For compilers
optimizing between files, I would hope a volatile annotation would
suffice, but some experimentation (or info from the vendor) may tell
us. As we learn of compilers that don't do what we want, we can
update the code to make them do so.
If we want to roll our own, I think the most portable choice may be to
use a "volatile char *" and scribble over each byte.
More information about the krbdev