c++ - 别名漏洞是否适用于签名字符?

标签 c++ char language-lawyer signed strict-aliasing

在 C++ 中,存在一个别名漏洞,它允许通过某些字符类型的指针读取或写入任何对象的对象表示。

这仅适用于charunsigned char还是也适用于signed char

最佳答案

不,该规定不适用于signed char

[basic.lval]

8 If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined:

  • [...]
  • a char, unsigned char, or std​::​byte type.

上面的引用包含与字符类型别名有关的最后一个项目符号。 signed char 被排除。

尽管如此,这也是主题的一部分 CWG Issue 350处理,因此可能会发生变化。考虑到问题所采取的方向,其目的是(最终,希望如此?)明确定义。

关于c++ - 别名漏洞是否适用于签名字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57653869/

相关文章:

c++ - 从 STM32CubeIDE 启动 QEMU 模拟器时出现问题

c++ - 生成错误 Makefile.win FLTK

c# - 获取 Control.KeyDown 上的字符?

c++ - 序列点和运算符优先级有什么区别?

c++ - 带有 char 指针的 strcat

c++ - 如何在 Xcode 中构建没有 calloc 转换结果的程序?

c - 为什么打印出 char 指针会产生整个数组而不是指针的内存地址?

c++ - C/C++ 如何在没有嵌套循环的情况下复制多维字符数组?

c++ - 为什么选择转换运算符的这种重载?

c - 术语 "format specifier"是术语 "conversion specifier"的同义词吗?