gcc/g++编译器-出现-fpermissive的问题
void fun1() { std::thread::id tid = std::this_thread::get_id(); printf("ID is %ld\n", *(long*)&tid); } void fun2() { std::thread::id tid = std::this_thread::get_id(); printf("ID is %ld\n", *(long*)&tid); } int main(int argc, char *argv[]) { std::thread t1(fun1); std::thread t2(fun2); std::thread::id t1_tid = t1.get_id(); //std::thread::id t2_tid = t2.get_id(); printf("t1 id is %ld\n", *(long*)&t1_tid); printf("t2 id is %ld\n", *(long*)& t2.get_id()); // 报错,需要中间变量 t1.join(); t2.join();
return 0; }
1. 问题:
编译时出现-fpermissive问题,问题描述是taking address of temporary [-fpermissive]
有一个简单粗暴的解决办法,就是在编译指令里面加入-fpermissive这一条命令,让代码由出错降为警告,从而编译通过,但是不要使用
2. 解决方法:
设置中间变量