Initializing an object to all zeroes

后端 未结 12 610
离开以前
离开以前 2020-12-03 01:27

Oftentimes data structures\' valid initialization is to set all members to zero. Even when programming in C++, one may need to interface with an external API for which this

12条回答
  •  Happy的楠姐
    2020-12-03 02:16

    In C I prefer using {0,} to the equivalent memset(). However gcc warns about this usage :( Details here: http://www.pixelbeat.org/programming/gcc/auto_init.html

    In C++ they're usually equivalent, but as always with C++ there are corner cases to consider (noted in other answers).

提交回复
热议问题