gpt4 book ai didi

c++ - 结构变量 = {0} 符号

转载 作者:行者123 更新时间:2023-11-30 00:50:42 25 4
gpt4 key购买 nike

我正在查看 Windows 套接字 API,它使用:

WSADATA wsaData = {0};

这个 {0} 到底有什么作用?

最佳答案

这意味着您正在将结构中的每个元素初始化为 0。

即使你写

WSADATA wsaData = {};

然后它还会将结构的每个成员初始化为零。

旁注:

静态存储持续时间对象总是初始化为零。来自标准:

Objects with static storage duration (3.7.1) shall be zero-initialized (8.5) before any other initialization takes place. Zero-initialization and initialization with a constant expression are collectively called static initialization; all other initialization is dynamic initialization. Objects of POD [plain old data] types (3.9) with static storage duration initialized with constant expressions (5.19) shall be initialized before any dynamic initialization takes place. Objects with static storage duration defined in namespace scope in the same translation unit and dynamically initialized shall be initialized in the order in which their definition appears in the translation unit. [Note:8.5.1 describes the order in which aggregate members are initialized. The initial- ization of local static objects is described in 6.7.]

关于c++ - 结构变量 = {0} 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24198158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com