struct declaration

后端 未结 2 1119
礼貌的吻别
礼貌的吻别 2021-01-26 07:47

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

First way:

struct x {};

Second way:

struct _x {} x;
         


        
2条回答
  •  孤街浪徒
    2021-01-26 08:38

    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.

提交回复
热议问题