Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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()/ZeroMemory()

STRUCT theStruct;
ZeroMemory( &theStruct, sizeof( theStruct ) );

or by value initialization:

STRUCT theStruct = {};

Although the two variants above are not equivalent in general:

  • treat padding differently
  • treat non-POD member variables differently

in case of POD structs used in Win32 they look equivalent.

Are there any cases when memset()/ZeroMemory() should be used instead of value initialization with Win32 POD structs?