Optimising away memset() calls?

Andrew Haley aph@redhat.com
Wed Oct 8 08:29:00 GMT 2014


On 08/10/14 03:15, Sandy Harris wrote:
> As I see it, though, and wrote in one thread:
> 
> " A real fix would make memset() do the right thing reliably; if the
> " programmer puts in memset( x, 0, nbytes) then the memory should
> " be cleared, no ifs or buts. I do not know or care if that means
> " changes in the compiler or in the library code or even both, but
> " the fix should make the standard library code work right, not
> " require adding a new function and expecting everyone to use it.
> 
> It seemed worth tossing this out for comment here.

That's not going to happen, given that memset_s() is a standard
idiom for this operation.

As it stands, even a call to memset_s() isn't sufficient: another
thread may not observe the memset_s() until a barrier has been
executed (and maybe not even then!) but I suppose it's better than
nothing.

Andrew.



More information about the Gcc-help mailing list