std::atomic<std::string>: Visual Studio 2013 (VC12) 中的访问冲突写入位置 0xFEEEEFEEE - 使用 std::atomic<int> 时不会发生
std::atomic<std::string>: Access violation writing location 0xFEEEEFEEE in Visual Studio 2013 (VC12) - does not occur when using std::atomic<int>
在 Visual Studio 2013 调试器中针对 x64 和 运行 在调试模式下编译的以下最小代码示例产生一个
Unhandled exception at ...: Access violation writing location
0xFEEEFEEE.
调试时,我发现访问冲突发生在 "return 0;" 语句中。
(当从没有调试器的控制台 运行 时,错误显示为 "Instruction at 0x... referenced memory at 0xddddddd... The memory could not be written.")。
#include <atomic>
#include <string>
int main()
{
std::atomic<std::string> a1("127.0.0.1:41001");
std::string ep1_1 = a1.load();
std::string ep1_2 = a1.load();
return 0;
}
std::atomic<std::string>
在标准 C++ 中是不合法的,因为 std::string
不可简单复制。不幸的是,没有要求编译器拒绝此代码,但也没有要求(也不可能)它会正常工作。
另请参阅:Does std::atomic<std::string> work appropriately?
在 Visual Studio 2013 调试器中针对 x64 和 运行 在调试模式下编译的以下最小代码示例产生一个
Unhandled exception at ...: Access violation writing location 0xFEEEFEEE.
调试时,我发现访问冲突发生在 "return 0;" 语句中。
(当从没有调试器的控制台 运行 时,错误显示为 "Instruction at 0x... referenced memory at 0xddddddd... The memory could not be written.")。
#include <atomic>
#include <string>
int main()
{
std::atomic<std::string> a1("127.0.0.1:41001");
std::string ep1_1 = a1.load();
std::string ep1_2 = a1.load();
return 0;
}
std::atomic<std::string>
在标准 C++ 中是不合法的,因为 std::string
不可简单复制。不幸的是,没有要求编译器拒绝此代码,但也没有要求(也不可能)它会正常工作。
另请参阅:Does std::atomic<std::string> work appropriately?