memset() or value initialization to zero out a struct?

后端 未结 8 2190
你的背包
你的背包 2020-11-27 10:29

In Win32 API programming it\'s typical to use C structs with multiple fields. Usually only a couple of them have meaningful values and all others have to be zer

8条回答
  •  孤独总比滥情好
    2020-11-27 11:13

    The value initialization because it can be done at compile time.
    Also it correctly 0 initializes all POD types.

    The memset() is done at runtime.
    Also using memset() is suspect if the struct is not POD.
    Does not correctly initialize (to zero) non int types.

提交回复
热议问题