user-0 提问: C语言结构体

回复:
user: user-1
content: for (int i=0;i<12;i++) {  plane[i].number=i+1;  plane[i].mark=0; } “变量赋值”和“变量初始化”不是一回事！ “变量赋值”发生在运行期，其写法遵循赋值语法规定。 “变量初始化”发生在编译期或运行期，其写法遵循初始化列表语法规定。

user: user-2
content: 引用 9 楼 loveqise 的回复:引用 8楼fefe82 的回复:在 C 语言里，全局变量只能用常量初始化。初始化了的结构体不算常量吗 不算。  6.6 Constant expressions Syntax 1 constant-expression:     conditional-expression  Description 2 A constant expression can be evaluated during translation rather than runtime, and accordingly may be used in any place that a constant may be.  Constraints 3 Constant expressions shall not contain assignment, increment, decrement, function-call, or comma operators, except when they are contained within a subexpression that is not evaluated. 4 Each constant expression shall evaluate to a constant that is in the range of representable values for its type.  Semantics 5 An expression that evaluates to a constant is required in several contexts. If a floating expression is evaluated in the translation environment, the arithmetic range and precision shall be at least as great as if the expression were being evaluated in the execution environment.  6 An integer constant expression shall have integer type and shall only have operands that are integer constants, enumeration constants, character constants, sizeof expressions whose results are integer constants, _Alignof expressions, and floating constants that are the immediate operands of casts. Cast operators in an integer constant expression shall only convert arithmetic types to integer types, except as part of an operand to the sizeof or _Alignof operator.  7 More latitude is permitted for constant expressions in initializers. Such a constant expression shall be, or evaluate to, one of the following: — an arithmetic constant expression, — a null pointer constant, — an address constant, or — an address constant for a complete object type plus or minus an integer constant expression.  8 An arithmetic constant expression shall have arithmetic type and shall only have operands that are integer constants, floating constants, enumeration constants, character constants, sizeof expressions whose results are integer constants, and _Alignof expressions. Cast operators in an arithmetic constant expression shall only convert arithmetic types to arithmetic types, except as part of an operand to a sizeof or _Alignof operator.  9 An address constant is a null pointer, a pointer to an lvalue designating an object of static storage duration, or a pointer to a function designator; it shall be created explicitly using the unary & operator or an integer constant cast to pointer type, or implicitly by the use of an expression of array or function type. The array-subscript [] and member-access . and -> operators, the address & and indirection * unary operators, and pointer casts may be used in the creation of an address constant, but the value of an object shall not be accessed by use of these operators.  10 An implementation may accept other forms of constant expressions.  11 The semantic rules for the evaluation of a constant expression are the same as for nonconstant expressions.

user: user-0
content: 引用 8楼fefe82 的回复:在 C 语言里，全局变量只能用常量初始化。初始化了的结构体不算常量吗

user: user-0
content: 引用 4楼赵4老师 的回复:将name和subname删掉。删掉也提示错误，而且删了结构就不完整了

user: user-1
content: 将name和subname删掉。

user: user-0

user: user-0
content: 引用 1楼paschen 的回复:没见到你plane的定义啊有啊！

user: user-3
content: 没见到你plane的定义啊

user: user-2
content: 在 C 语言里，全局变量只能用常量初始化。

user: user-0
content: 引用 6楼user-4 的回复:你的结构体包含了四个字段，你只给前面两个int类型的字段初始化了，那后面的name和subname呢？结构体不一定全部要初始化啊，只要部分有初始值就行

user: user-4
content: 你的结构体包含了四个字段，你只给前面两个int类型的字段初始化了，那后面的name和subname呢？