alex <nospam@nospam.com> writes:
> On Wed, 11 Jul 2012 11:59:42 -0400, Eric Sosman wrote:
>> A problem with the approach you've outlined is that the
>> checksum computation will include the values of any padding bytes -- the
>> size of `z' in your example almost begs for some padding bytes to be
>> inserted. Since padding bytes are not necessarily preserved when
>> assigning structs or even when assigning to struct elements, a checksum
>> that includes padding bytes is unlikely to be very useful.
>
> Are you sure about this?? I would expect a struct assign/deepcopy to be
> implemented "under the hood" using memcpy(), not { s1.a=s2.a;
> s1.b=s2.b; } etc. Pretty sure that's what GCC does.
A compiler can do it either way. Using the equivalent of a memcpy()
call is certainly a likely approach, but there's no guarantee that
it's done that way.
Code that assumes padding bytes are preserved is likely to work
perfectly until the moment you demonstrate it to an important client.
--
Keith Thompson (The_Other_Keith)
kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"