更新时间:2023-02-12 19:15:18
你说得对,它不应该编译,而且在大多数编译器上,它不编译.(请具体说明哪个编译器/版本没有给你一个编译器错误)
You are right that it should not compile, and on most compilers, it does not compile.(Please specify exactly which compiler/version is NOT giving you a compiler error)
我只能假设编译器知道 (i | i) == i
和 (i & i) == i
的身份并且正在使用它们身份来优化表达式,只留下变量 i
.
I can only hypothesize that the compiler knows the identities that (i | i) == i
and (i & i) == i
and is using those identities to optimize away the expression, just leaving behind the variable i
.
这只是一个猜测,但对我来说很有意义.
This is just a guess, but it makes a lot of sense to me.