运算符优先级手册页中的 etc 是什么?
what is that `etc` in operator precedence man page?
man operator
在 macOS 10.12 上显示 etc.
,这是什么,联机帮助页错误?
OPERATOR(7) BSD Miscellaneous Information Manual OPERATOR(7)
NAME
operator -- C operator precedence and order of evaluation
DESCRIPTION
Operator Associativity
-------- -------------
() [] -> . left to right
! ~ ++ -- - (type) * & sizeof right to left
* / % left to right
+ - left to right
<< >> left to right
< <= > >= left to right
== != left to right
& left to right
^ left to right
| left to right
&& left to right
|| left to right
?: right to left
= += -= etc. right to left
, left to right
FILES
/usr/share/misc/operator
BSD June 9, 1993 BSD
etc.
代表拉丁文 et cetera,字面意思是 "and the rest"。这里表示"assignment operators"的全族:*=
、/=
、%=
等。
you mentioned does not list all the assignment operators, so it uses etc.
(etc == et cetera) 表示这不是一个详尽的清单。这不是错误,etc.
也不是 C 语言中的运算符/关键字(想提,FWIW)。
other version 列出了所有这些。
= += -= *= /= %= <<= >>= &= ^= |=
完整列表见第 6.5.16 章,C11
。
虽然您已经有了即时问题的答案——等只是意味着他们没有列出每一个赋值运算符在这里——您可能会从一条额外的信息中受益:
严格来说,C 中没有运算符优先级。这意味着 C 标准没有指定。相反,它为表达式指定了一个 grammar,其符号有点类似于 BNF(它使用单个冒号而不是 ::=
,斜体而不是尖括号,粗体文本而不是双引号等)。它看起来像这样的例子:
N1570(最新的 C11 草案),§6.5.1:
primary-expression :
identifier
constant
string-literal
( expression )
generic-selection
这等同于以下 BNF:
<primary-expression> ::= <identifier> | <constant> | <string-literal>
| "(" <expression> ")" | <generic-selection>
从遍及 §6.5 的完整语法中,可以推断出“运算符优先级”,但有一个问题条件运算符 (?:
):它不允许赋值表达式出现在冒号的右侧,所以虽然它通常是以高于赋值的优先级列出,您必须将赋值放在括号中以使其成为 主表达式 (请参阅上面的语法片段)。关于这个有一个nice explanation on cppreference.com。
man operator
在 macOS 10.12 上显示 etc.
,这是什么,联机帮助页错误?
OPERATOR(7) BSD Miscellaneous Information Manual OPERATOR(7)
NAME
operator -- C operator precedence and order of evaluation
DESCRIPTION
Operator Associativity
-------- -------------
() [] -> . left to right
! ~ ++ -- - (type) * & sizeof right to left
* / % left to right
+ - left to right
<< >> left to right
< <= > >= left to right
== != left to right
& left to right
^ left to right
| left to right
&& left to right
|| left to right
?: right to left
= += -= etc. right to left
, left to right
FILES
/usr/share/misc/operator
BSD June 9, 1993 BSD
etc.
代表拉丁文 et cetera,字面意思是 "and the rest"。这里表示"assignment operators"的全族:*=
、/=
、%=
等。
you mentioned does not list all the assignment operators, so it uses etc.
(etc == et cetera) 表示这不是一个详尽的清单。这不是错误,etc.
也不是 C 语言中的运算符/关键字(想提,FWIW)。
other version 列出了所有这些。
= += -= *= /= %= <<= >>= &= ^= |=
完整列表见第 6.5.16 章,C11
。
虽然您已经有了即时问题的答案——等只是意味着他们没有列出每一个赋值运算符在这里——您可能会从一条额外的信息中受益:
严格来说,C 中没有运算符优先级。这意味着 C 标准没有指定。相反,它为表达式指定了一个 grammar,其符号有点类似于 BNF(它使用单个冒号而不是 ::=
,斜体而不是尖括号,粗体文本而不是双引号等)。它看起来像这样的例子:
N1570(最新的 C11 草案),§6.5.1:
primary-expression :
identifier
constant
string-literal
( expression )
generic-selection
这等同于以下 BNF:
<primary-expression> ::= <identifier> | <constant> | <string-literal>
| "(" <expression> ")" | <generic-selection>
从遍及 §6.5 的完整语法中,可以推断出“运算符优先级”,但有一个问题条件运算符 (?:
):它不允许赋值表达式出现在冒号的右侧,所以虽然它通常是以高于赋值的优先级列出,您必须将赋值放在括号中以使其成为 主表达式 (请参阅上面的语法片段)。关于这个有一个nice explanation on cppreference.com。