use of memset and optimization
ssen at MIT.EDU
Fri Nov 8 10:46:00 EST 2002
I was able to compile the sample file with -O3 without seeing any
inlining/elimination by passing -fno-builtin (gcc 3.2 on sparc/solaris8).
This might be a reasonable known alternative to disabling optimization
completely if this issue is a concern.
On Fri, 8 Nov 2002, Tom Yu wrote:
> By examining the assembly output for the following test C file, I
> conclude that gcc 3.0.3 on sparc/solaris8, when given the "-O" flag,
> inlines the call to strncpy() for g() and h() and removes the call to
> memset(). For f(), it doesn't remove the call to memset. Using
> either gcc 2.95.3 or sun's C compiler, with any non-zero level of
> optimization, does not appear to optimize out the call to memset(),
> though gcc 2.95.3 does seem to inline the memset() calls.
> Both gcc 3.0.3 and gcc 2.95.3 inline but do not eliminate the memset()
> call in h2(), which is valid behavior -- the "static" storage duration
> qualifier means that some other function, e.g. encrypt(), may retain a
> pointer to that object after h2() returns.
More information about the krbdev