3 ms·
I'm confused. Is the memset to the temporary volatile void* observable or not, and is the temporary possibly eliminated?
by 1ris 5y ago
I'm confused. Is the memset to the temporary volatile void* observable or not, and is the temporary possibly eliminated?
- ncmncm 5y agoCasting the pointer passed to memset has no effect. The compiler knows what the storage pointed-to is: a temporary object. The compiler knows that memset does not allow a pointer to the object to escape from view. So, it can eliminate the call. Calling C11's memset_s, or MS's SecureZeroMemory, or FreeBSD's explicit_bzero, has the effect, to the compiler, of making the object observable, so that operations on it will not be optimized away. There is no way to express this locally within the language; you must rely on facilities provided by a Standard or your platform, or on the dodgy linkage trick cited elsewhere.