结构的初始序列是什么? [英] What's the struct's initial sequence?

查看:300
本文介绍了结构的初始序列是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到了初始序列概念。通过标准初始序列短语只给出3个结果,并且它们不给定义。

I came across the initial sequence concept. Serching through the Standard for initial sequence phrase gives only 3 results and they don't give a definition.

N3797 :: 9.5 / 1 [class.union]


-layout union包含共享公共初始序列的几个标准布局结构
(9.2),如果此
标准布局联合类型的对象包含标准布局-layout
structs,允许检查任何
标准布局结构成员的公共初始序列;

If a standard-layout union contains several standard-layout structs that share a common initial sequence (9.2), and if an object of this standard-layout union type contains one of the standard-layout structs, it is permitted to inspect the common initial sequence of any of standard-layout struct members;

我想看一个例子,这个例子是演示的引用。

I wish to look at an example which is demostrated that quote.

推荐答案

我相信它在谈论这种事:

I believe it's talking about this kind of thing:

union U {
    struct S {
        int a;
        int b;
        int c;
    }
    struct T {
        int x;
        int y;
        float f;
    }
};

这说明可以访问 USa UTx ,并且它们将是等效的。同上美国 U.T.y 当然。但在设置 U.S.c 后访问 U.T.f 将是未定义的行为。

It's saying that it's OK to access either U.S.a or U.T.x and that they will be equivalent. Ditto for U.S.b and U.T.y of course. But accessing U.T.f after setting U.S.c would be undefined behaviour.

这篇关于结构的初始序列是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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