This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: PODs vs memset
"AlisdairM" <alisdair.meredith@uk.renaultf1.com> writes:
| Paolo Carlini wrote:
|
| > ... restricting now the attention to "scalars" (i.e., what our
| > library __is_scalar implements, no member pointers), I still think it
| > makes sense to use memset elsewhere too, not only in valarray...
|
| <delurk/>
| Be careful with memset-ing PODs as a matter of policy.
I believe Paolo clearly said he was intending to use memset for
objects of *scalar types*, not POD. So, I don't think there is
anything there to alert the world about.
| Generally, it is safe to memset PODs passed by value, but not by
| reference. The problem case is a derived class with a POD base - in
| this situation you are no longer allowed to memset the POD, and if you
| pass a derived object to a function taking base by reference (which the
| called-function cannot know) then you hit undefined behaviour.
libstdc++ being the GNU implementation of the ISO C++ runtime, we must
indeed be careful about the GCC ABI -- and we should take advantage
of that ABI when beneficial. Would you mind pointing me at
the ABI where GCC is permitted to reuse the tail of a base class that
is POD?
-- Gaby