部分定义的静态对象的未初始化成员是否保证初始化为 0?

Are uninitialized members of partially-defined static objects guaranteed initialized to 0?

我知道未初始化的静态变量存储在 BSS 中,因此保证使用所有 0(对于它们各自的数据类型大小)进行初始化。

此外,在 C 中,静态变量可以定义为编译时常量(仅)。

"partially initialized" 静态变量的定义行为是什么(我不确定这是不是正确的术语),示例如下:

// main.c

#include <stdbool.h>
#include <stdio.h>

static struct Foo
{
  bool f[2][3];
} g_table =      { { { true, true, false },
                     { true } } };

int main( int argc, char* argv[] )
{
  printf( "%d %d %d\n", g_table.f[0][0], g_table.f[0][1], g_table.f[0][2] );
  printf( "%d %d %d\n", g_table.f[1][0], g_table.f[1][1], g_table.f[1][2] );
  return 0;
}

.

$ gcc --version && gcc -g ./main.c && ./a.out 
gcc (GCC) 9.2.1 20190827 (Red Hat 9.2.1-1)
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

1 1 0
1 0 0

上面的"partially initialized,",我指的是g_table的初始化,这里并不是成员数组的所有元素都被显式定义。上面的例子暗示静态对象g_table的非显式初始化部分被初始化为0这是guaranteed/defined行为吗?


注意:我知道存在关于静态变量初始化和未初始化静态变量的默认值的 Stack Overflow 问题;我无法找到关于此 "partial initialization" 的现有问题(如果我所描述的内容存在更正确的术语,请告诉我)。

所有剩余元素都初始化为零(对于算术类型)或空指针(对于指针)。 C 2018 6.7.9 21 说:

If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.

6.7.9 10 表示具有静态存储持续时间的对象有效地初始化为零:

… If an object that has static or thread storage duration is not initialized explicitly, then:

— if it has pointer type, it is initialized to a null pointer;

— if it has arithmetic type, it is initialized to (positive or unsigned) zero;

— if it is an aggregate, every member is initialized (recursively) according to these rules, and any padding is initialized to zero bits;

— if it is a union, the first named member is initialized (recursively) according to these rules, and any padding is initialized to zero bits;