Too*_*sie 5 c++ signals volatile
在我的平台(X86、Fedora、gcc 9.1.1)sig_atomic_t上,类型定义为普通的int.
在 C++ 标准中,sig_atomic_t始终与volatile限定符一起使用。
我明白为什么volatile需要,但为什么它不是类型的一部分呢?
就像是:
using sig_atomic_t = volatile int;
Run Code Online (Sandbox Code Playgroud)
这是从 C 继承的。C 定义虽然允许sig_atomic_tvolatile 限定,但并不要求它。我查看过的标准文档(N1570)中使用的所有示例均以volatile sig_atomic_t.
如今,在可行的情况下,使用标头std:atomic中指定的其他功能可能会更好。(另请参阅cppreference 上的sig_atomic_t。)<atomic>