Skip to content

Commit

Permalink
Merge pull request #71 from Mq-b/PR-ub-fix
Browse files Browse the repository at this point in the history
修改 `undef.md` 中关于左移与右移的问题
  • Loading branch information
archibate authored Dec 17, 2024
2 parents 97c100c + 77f7730 commit 0aca22a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/undef.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,19 @@ i << 0; // 可以
i << -1; // 错!
```

但是你还需要考虑一件事情:**隐式转换**,或者直接点说:**整数提升**

- 在 C++ 中算术运算符不接受小于 int 的类型进行运算。如果你觉得可以,那只是隐式转换,整形提升了。

```cpp
std::uint8_t c{ '0' };
using T1 = decltype(c << 1); // int
```
即使移位大于等于 8 也不成问题。
---
对于有符号整数,左移还不得破坏符号位
```cpp
Expand Down

0 comments on commit 0aca22a

Please sign in to comment.