我正在使用Visual Studio 17 v15.0和Win 10 Anniversary Update SDK。
我使用cl /EHsc /O2 /DUNICODE /bigobj /await /std:c++latest
或/MT
构建了以下代码(基本上为sample in github repo)。它编译没有错误。
如果我在当前目录中出现``message.png“不时运行,则会抛出异常,捕获并报告printf,然后退出而不会崩溃。
如果我在当前目录中出现``message.png“ 时运行,”Hello World!“将被打印,然后无缘无故崩溃。
奇怪的是如果我在GDB调试器中运行它,GDB总是说程序正常退出(事实上没有发生崩溃)。
GDB输出:
MD
代码:
[New Thread 1364.0x2324]
[New Thread 1364.0x624]
[New Thread 1364.0x12cc]
[New Thread 1364.0x58c]
[New Thread 1364.0x1134]
[New Thread 1364.0x10d8]
[New Thread 1364.0x18a8]
[New Thread 1364.0x1794]
[New Thread 1364.0x20e8]
[New Thread 1364.0x2204]
[New Thread 1364.0x1030]
[New Thread 1364.0x1474]
Hello world!
[Thread 1364.0x10d8 exited with code 0]
[Thread 1364.0x624 exited with code 0]
[Thread 1364.0x20e8 exited with code 0]
[Thread 1364.0x1794 exited with code 0]
[Thread 1364.0x18a8 exited with code 0]
[Thread 1364.0x58c exited with code 0]
[Thread 1364.0x1134 exited with code 0]
[Thread 1364.0x12cc exited with code 0]
[Thread 1364.0x8d0 exited with code 0]
[Thread 1364.0x2324 exited with code 0]
[Thread 1364.0x1b38 exited with code 0]
[Thread 1364.0x2204 exited with code 0]
[Thread 1364.0x1030 exited with code 0]
[Thread 1364.0x1474 exited with code 0]
[Inferior 1 (process 1364) exited normally]
答案 0 :(得分:0)
结果hstring
返回的AsyncSample().get()
未终止,因此printf
崩溃。
try
{
auto ans = AsyncSample().get();
printf("[%u]: ", ans.size());
auto s = ans.c_str();
for (uint32_t i = 0; i < ans.size(); i++) {
printf("%lc", s[i]);
}
putchar('\n');
}