On 25 Jul 2013, at 09:11, Hans Petter Selasky <[email protected]> wrote:
> The structure looks like some size, so bzero() might run faster than memset()
> depending on the compiler settings. Should be profiled before changed!
They will generate identical code for small structures with known sizes. Both
clang and gcc have a simplify libcalls pass that recognises both functions and
will elide the call in preference to a small set of inline stores.
However(), memset is to be preferred in this idiom because the compiler
provides better diagnostics in the case of error:
bzero.c:9:22: warning: 'memset' call operates on objects of type 'struct foo'
while the size is based on a different type 'struct foo *'
[-Wsizeof-pointer-memaccess]
memset(f, 0, sizeof(f));
~ ^
bzero.c:9:22: note: did you mean to dereference the argument to 'sizeof' (and
multiply it by the number of elements)?
memset(f, 0, sizeof(f));
^
The same line with bzero(f, sizeof(f)) generates no error.
David
signature.asc
Description: Message signed with OpenPGP using GPGMail
