Code review comment for lp://staging/~smspillaz/compiz-core/fix_894688

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

On Thu, 15 Dec 2011, Daniel van Vugt wrote:

> The main reason (other than stylistic and religious) for not using memcmp on structs is because structs are often not perfectly aligned and so contain padding bytes. The padding bytes are uninitialized, unpredictable and inaccessible unless you also guarantee each struct has first been memset(&s,0,sizeof(s)).
>
> In general, memcmp is highly optimized for the architecture and is in fact faster than a bespoke operator. However you can't use memcmp with structs unless you guarantee they're always fully initialized with memset to the full sizeof(yourstruct).

Thanks Daniel - I didn't know that, so I'll keep it in mind (and probably
just implement operator==)

> --
> https://code.launchpad.net/~smspillaz/compiz-core/fix_894688/+merge/84058
> You are the owner of lp:~smspillaz/compiz-core/fix_894688.
>

« Back to merge proposal