Operator precedence table for the C programming language

本小妞迷上赌 提交于 2019-11-26 07:49:25

问题


What would a correct operator precedence table that lists all operators in the C language look like?

I have made extensive searches on the web, and found many such precedence tables. Alas, I haven\'t found a single one filling these requirements:

  • Lists all operators in the C language as defined in ISO 9899:2011, without mixing in any C++ operators.
  • Lists the operators in the complete and correct priority order.

回答1:



Explanation

Prec. denotes operator precedence, where group 1 has the highest precedence and group 17 the lowest.

Assoc. denotes operator associativity, where such is applicable. Associativity can be either left-to-right or right-to-left.

Sources

My ambition with this post is to provide a operator precedence table on-site at Stack Overflow, which is correct and canonical. This operator precedence table corresponds directly to chapter 6.5 of ISO 9899:2011, where we can read (6.5/3):

The grouping of operators and operands is indicated by the syntax. 85)

And then as a comment, in the informative (not normative) foot note:

85) The syntax specifies the precedence of operators in the evaluation of an expression, which is the same as the order of the major subclauses of this subclause, highest precedence first. /--/

Within each major subclause, the operators have the same precedence. Left- or right-associativity is indicated in each subclause by the syntax for the expressions discussed therein.

All formal operator names from the table are taken from chapter 6.5, where such a name could be found in normative text. Informal names were included in the cases where the programmer community might be more familiar with another name than the one given in the standard.




回答2:


Here:

http://basen.oru.se/c/operators.html

(I added _Alignof, which I think is the only new operator in C11, to my own table, and published it there. Maybe that's cheating? Comments and suggestions on how to improve the table are welcome.)




回答3:


This site has a pretty great precedence table:

http://www.difranco.net/compsci/C_Operator_Precedence_Table.htm



来源:https://stackoverflow.com/questions/17369090/operator-precedence-table-for-the-c-programming-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!