Skip to content

败犬日报 2025-01-23

1. 1 << (-1) 是不是未定义行为

是。

https://zh.cppreference.com/w/cpp/language/operator_arithmetic 记载:

任何情况下,如果右操作数的值为负或不小于左操作数中的位数,那么行为未定义。