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

前端 未结 7 858
南方客
南方客 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:16

    in c++11:

    struct A {
        int x = 10;
        int y = 100;
        int z = 0;
    };
    

    old style c++

    struct A {
        int x;
        int y;
        int z;
        A() : x( 10 ), y( 100 ), z( 0 ) {} //constructor
    };
    

提交回复
热议问题