Any reason to prefer memset/ZeroMemory to value initialization for WinAPI structs?

前端 未结 7 790
南方客
南方客 2020-12-31 01:42

In Win32 programming a handful of POD structs is used. Those structs often need to be zeroed out before usage.

This can be done by calling memset()/

相关标签:
7条回答
  • 2020-12-31 02:18

    The only reason (that I can foresee) to not use value initialization for 'zeroing' is if you have special versions of memset/ZeroMemory(such as an SSE based one), or you need to avoid problems with the compiler(referring to MSVC here, as from VS2008 memset will never become an intrinsic, but with some clever coding(not using asm) you can force the intrinsic(REP STOS))

    0 讨论(0)
提交回复
热议问题