这种类型的初始化叫什么?

What's this type of initialization called?

我在 Vulkan 教程中看到代码如下:

VkImageMemoryBarrier imageMemoryBarrier = {
 
   .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
   .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
   .oldLayout = VK_IMAGE_LAYOUT_GENERAL,
   .newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
            /* .image and .subresourceRange should identify image subresource accessed */ 
};

如果我只列出没有成员 '.member_name =' 的枚举,那将是聚合初始化,对吧?但这叫什么?这个 class 在 .srcAccessMask 之前还有其他成员,我假设所有其他没有提到的成员都是零初始化的?但是如果我不知道它叫什么,就很难查找它。另外,我记得像这样的东西是一个新的 C 特性,但它在 Visual Studio 中为我用 C++ 编译。这是一个 C++ 特性,对吧?

这仍然是聚合初始化,自 C++20 起支持语法 designated initializers

T object = { .designator = arg1 , .designator { arg2 } ... }; (3) (since C++20)
T object { .designator = arg1 , .designator { arg2 } ... };   (4) (since C++20)

关于初始化程序中未提及的成员:

For a non-union aggregate, elements for which a designated initializer is not provided are initialized the same as described above for when the number of initializer clauses is less than the number of members (default member initializers where provided, empty list-initialization otherwise):

顺便说一句:C++ 中的规则与 C 中的规则不同。

Note: out-of-order designated initialization, nested designated initialization, mixing of designated initializers and regular initializers, and designated initialization of arrays are all supported in the C programming language, but are not allowed in C++.

Also, I remember something like this being a new C feature

这不是新的。它是在 C99 中添加的。未明确初始化的成员被清零。

https://port70.net/%7Ensz/c/c11/n1570.html#6.7.9

@songyuanyao 添加了一个很好的答案,但为了完整性:它被称为指定的初始化程序。