Skip to content

Commit 0aca22a

Browse files
authored
Merge pull request #71 from Mq-b/PR-ub-fix
修改 `undef.md` 中关于左移与右移的问题
2 parents 97c100c + 77f7730 commit 0aca22a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/undef.md

+13
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,19 @@ i << 0; // 可以
314314
i << -1; // 错!
315315
```
316316

317+
但是你还需要考虑一件事情:**隐式转换**,或者直接点说:**整数提升**
318+
319+
- 在 C++ 中算术运算符不接受小于 int 的类型进行运算。如果你觉得可以,那只是隐式转换,整形提升了。
320+
321+
```cpp
322+
std::uint8_t c{ '0' };
323+
using T1 = decltype(c << 1); // int
324+
```
325+
326+
即使移位大于等于 8 也不成问题。
327+
328+
---
329+
317330
对于有符号整数,左移还不得破坏符号位
318331
319332
```cpp

0 commit comments

Comments
 (0)