我知道void (*)(int)
是函数指针但是是什么void(int)
?
它用于std::function
模板.
说我有一个功能void fun(int){}
:decltype(&fun)
给予void(*)(int)
但decltype(fun)
给予void(int)
我遇到这个编译错误
function std::atomic::is_lock_free() const: error: undefined reference to '__atomic_is_lock_free'
在Linux上使用gcc 4.7.2编译代码如下所示.
struct S {
int a;
int b;
};
std::atomic<S> s;
cout << s.is_lock_free() << endl;
Run Code Online (Sandbox Code Playgroud) 我在 RHEL6 和 RHEL7 上安装了 gcc 5.2.1,看起来 _GLIBCXX_USE_CXX11_ABI 被禁用了。即使我手动运行它也不起作用-D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
。这意味着我不会获得小字符串优化功能。例如,以下代码的输出始终为 8 和“micro not set”。对于 SSO,如果我们查看代码 bits/basic_string.h,std::string 的大小应至少为 16。有什么解决办法吗?
#include <string>
#include <iostream>
int main()
{
std::cout << sizeof(std::string) << std::endl;
#if _GLIBCXX_USE_CXX11_ABI
std::cout << "macro set" << std::endl;
#else
std::cout << "macro not set" << std::endl;
#endif
}
Run Code Online (Sandbox Code Playgroud) 我不知道我的简单std :: thread代码(下面列出的)有什么问题.在Ubuntu上使用gcc 4.6或最新的4.7时总会崩溃.我用命令编译它g++ -std=c++11 myfile.cpp
和g++ -std=gnu++11 myfile.cpp
.
#include <iostream>
#include <thread>
using namespace std;
void func() {
cout << "hello\n";
}
int main()
{
std::thread thrd(func);
thrd.join();
}
Run Code Online (Sandbox Code Playgroud)
核心转储的callstack类似于下面的内容
#0 0x00007ffff7539445 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff753cbab in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff7b35b0d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff7b33c16 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff7b33c43 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff7b33e6e in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00007ffff7b8829c in std::__throw_system_error(int) …
Run Code Online (Sandbox Code Playgroud)