64,648
社区成员
发帖
与我相关
我的任务
分享
#include <sstream>
void func0() {
// 这里在调用 << 'I'; 或 .put('I') 的时候出错:
// EXC_BAD_ACCESS(code=0,address=0xffffffff00000000),有有汇编的报错,我看不懂
// 环境是 Mac + XCode,以 arm64(64位) 架构跑必崩溃,以 armv7(32位) 架构跑则完全正常
std::stringstream ss;
ss << "I";
printf("func0.ss = %s\n", ss.str().c_str());
}
void func1() {
// 执行没问题
func0();
std::stringstream ss;
ss << "I";
printf("func1.ss = %s\n", ss.str().c_str());
}
void func2() {
// 执行没问题
func1();
std::stringstream ss;
ss << "A";
printf("func2.ss = %s\n", ss.str().c_str());
}
int main() {
func2();
return 0;
}
void func0() {
// 这里在调用 << 'I'; 或 .put('I') 的时候出错:
// EXC_BAD_ACCESS(code=0,address=0xffffffff00000000),有有汇编的报错,我看不懂
// 环境是 Mac + XCode,以 arm64(64位) 架构跑必崩溃,以 armv7(32位) 架构跑则完全正常
std::stringstream ss;
ss << "I";
//make a const ref to avoid early dtor
std::string const& x = ss.str();
printf("func0.ss = %s\n", x.c_str());
}
your code seems good. your compiler may not take good care of this