4 ms·
> Code external to yours may make assumptions about what lies in your padding, either by doing memcmp's, or adding new fields in a later version of the struct a
by iforgotpassword 8y ago
> Code external to yours may make assumptions about what lies in your padding, either by doing memcmp's, or adding new fields in a later version of the struct and intending it to be ABI compatible between modules.
The content of the padding between members can arbitrarily change during assignments of members, so code relying on the content of it is broken anyways. In the case of an extended struct both methods are equally broken if you don't recompile your module with the updated definition of the struct. Your memset will still have the old size of the struct as the third argument.
- hedora 8y agoIf you use: sizeof(struct_instance) the compiler will automatically update the size passed to memcpy. (I like passing the instance to sizeof and not the type, just in case the type of the thing being copied changes in a future version of the code.)
- iforgotpassword 8y agoThat is exactly what I said: > ...if you don't recompile your module with the updated definition of the struct... And once you recompiled, the C99 version with the pretty initializer is fixed as well, so there is no advantage in using memset regarding this.