use of memset and optimization

Tom Yu tlyu at MIT.EDU
Fri Nov 8 12:10:00 EST 2002


>>>>> "sommerfeld" == Bill Sommerfeld <sommerfeld at orchard.arlington.ma.us> writes:

>> This function is not marked to be inlined.  Therefore from my
>> perspective the compiler's behavior is incorrect because
>> the compiler is making an assumption as to what the memset() function
>> does.  

sommerfeld> You may be doing inter-module optimizations (deferring
sommerfeld> code generation to "link" time -- both sun and hp let you
sommerfeld> do this in their vendor compilers).

Yeah.  The standard doesn't require the implementation to provide
access to intermediate translation phases, so if the compiler knows
that it can inline some code, it certainly may do so if it knows that
there won't be any change in resulting program behavior.

sommerfeld> at this point, the code generator can *know* that you are
sommerfeld> using the system version of memset().

Also, I believe a hosted implementation is required to behave as if
you were calling the standard function, regardless of how it's
implemented.  A conforming program compiled by a hosted implementation
can't make the assumption that a call to memset() will generate an
external reference to an implementation of memset() in a separate
translation unit of the program.  This results in undefined behavior,
since memset() is always reserved by a hosted implementation as an
identifier with external linkage regardless of whether <string.h> is
included.  The standard is a little unclear on whether a freestanding
implementation reserves identifiers of the standard library that a
freestanding implementation is not required to implement, though.

---Tom



More information about the krbdev mailing list