结构声明 [英] struct declaration

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

问题描述

这两种声明结构体的方式有什么区别?

第一种方式:

struct x {};

第二种方式:

struct _x {} x;

解决方案

第一个只定义了 struct x 类型.第二个定义了类型 struct _x 定义了一个名为 x 的类型的变量.

虽然这可能不是您的想法,但以下划线开头的名称如 _x 是在文件范围内保留的,因此除非这是在其他范围内,否则第二个具有未定义的行为.

What is the difference between these 2 ways of declaring a struct?

First way:

struct x {};

Second way:

struct _x {} x;

解决方案

The first defines only the type struct x. The second defines the type struct _x and defines a variable of that type named x.

Though it's probably not what you had in mind, names starting with an underscore like _x are reserved at file scope, so unless this is inside some other scope, the second has undefined behavior.

这篇关于结构声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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