恰好不是由指定初始化命名字段是什么? [英] What happens to fields not named by a designated initializer?

查看:127
本文介绍了恰好不是由指定初始化命名字段是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C99(而不是C ++),有可能初始化使用此语法结构:

In C99 (and not in C++), it's possible to initialize structs using this syntax:

struct info
{
    char    name[8+1];
    int     sz;
    int     typ;
};

struct info  arr[] =
{
    [0] = { .sz = 20, .name = "abc" },
    [9] = { .sz = -1, .name = "" }
};

发生了未指定的领域是什么?

What happens to the unspecified fields?

推荐答案

它们将被清零。从C99标准和教派; 6.7.8(初始化)/ 21,

They are zeroed. From the C99 standard §6.7.8 (Initialization)/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.

这篇关于恰好不是由指定初始化命名字段是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆