为什么 a 和 b 在下面的代码中共享相同的地址
Why do a and b share the same address in the following code?
为什么在这种情况下会触发静态断言?由于 64 位地址行和 char 是单个字节,它们是否位于同一地址?
#include <type_traits>
int main()
{
char a='a';
char b='b';
static_assert ( &a == &b, " ERROR: Same addr" ) ;
}
main.cpp: In function ‘int main()’:
main.cpp:9:3: error: static assertion failed: ERROR: Same addr
你的逻辑倒过来了。 static_assert
在条件为false
时触发,即两个对象没有相同的地址。
a
和b
位于不同的地址。你的断言是错误的。您的断言失败,因为两个地址不同。尝试
static_assert ( &a != &b, " ERROR: Same addr" ) ;
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 将数组的地址分配给变量并删除
- 空基优化子对象的地址
- 禁用地址共享注册表不起作用
- 不同类的虚拟函数共享相同的(无效?)内存地址
- ptrA = ptrB 是否等同于 ptrA = &*ptrB?,空值是否共享一个地址空间?
- 我可以检查共享内存中是否存在地址
- 查询与将地址分配给共享_ptr有关
- 引用如何共享内存地址
- 共享库中的成员函数指针地址
- CUDA:结构体的共享数据成员和对该结构体的引用成员具有不同的地址和值
- 两个对象似乎共享相同的地址
- 为什么 a 和 b 在下面的代码中共享相同的地址
- 尝试使用pthreads访问共享数据数组时,出现“无法访问内存地址”错误
- 如何判断共享库在进程地址空间中的加载位置
- 将memmove函数与临时指针共享相同的地址
- CUDA 运行时错误:未指定的启动失败 & 超出范围的共享或本地地址
- 如何为共享内存映射选择固定地址
- 其他对象中的对象是否真的共享相同的地址
- 为什么字符串形参与实参共享相同的地址