++ structure.field中的运算符层次结构

问题描述 投票:1回答:1

示例:

++structure.field;

increments field而不是给“错误的类型实参增加”,尽管是++和。运算符是相等的分层ergo:应该从左到右执行。

我在这里想念东西吗?

c increment operator-precedence associativity
1个回答
4
投票

前缀和后缀++具有不同的优先级。 .的优先级高于prefix增量运算符,如cppreference.com所示。

Excerpt of the operator precedence and associativity table from cppreference.com

.postfix增量具有相同的优先级。如果您写了structure.field++,那么它们将具有相同的优先级,并且可以使用关联性将歧义化为(structure.field)++而不是structure.(field++)

© www.soinside.com 2019 - 2024. All rights reserved.