can someone please clarify the difference between the include options #include <atomic>
and #inlucde <cstdatomic>
?
有人能澄清一下include选项#include
I'm guessing that there is none, because its the same behaviour?
我猜没有,因为它是一样的行为?
I am asking this because on my debian system I've got only the atomic and on my kubuntu system I've got the cstdatomic.
我问这个是因为在我的debian系统中我只有原子系统,在kubuntu系统中我有cstdatomic。
-
compiler on Debian: version 4.7.2 (Debian 4.7.2-4)
Debian编译器:4.7.2版本(Debian 4.7.2-4)
-
compiler on Kubuntu: version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
Kubuntu: 4.6.3版本(Ubuntu/Linaro 4.6.3-1ubuntu5)
2 个解决方案
#1
8
<atomic>
is the C++ atomic operations library.
<cstdatomic>
is the C++ version of the C atomic operations library.
Both will give you e.g., std::atomic_char
but only the C++ version has std::atomic<T>
.
两者都将给出例如std::atomic_char,但只有c++版本具有std::atomic
As a general rule, C headers should be used in C++ by removing the .h
extension and prepending c
to the name: stdatomic.h
becomes cstdatomic
. That will include the C headers into the namespace std
.
一般来说,在c++中,应该通过删除.h扩展名和将C前置到名称:stdatomic来使用C标头。h变得cstdatomic。这将把C标头包含到名称空间std中。
Note also that stdatomic.h
(and cstdatomic
hence) is C11 and atomic
is C++11, which might explain the difference in compiler support.
还要注意stdatomic。h(因此是cstdatomic)是C11, atomic是c++ 11,这可能解释了编译器支持方面的差异。
#2
15
Both existing answers are wrong, and most comments too.
现有的答案都是错误的,大多数评论也是如此。
<cstdatomic>
is not a header defined in any standard.
It was defined in old C++0x drafts but is not in the final C++11 standard, only <atomic>
is. So it was included as part of GCC 4.4's experimental C++0x support, but then renamed for later releases when it got renamed in the C++0x drafts (which was done in 2009 by N2992).
它是在旧c++ 0x草稿中定义的,但不是在最终的c++ 11标准中,只有 <原子> 是。因此,它被作为GCC 4.4实验性的c++ 0x支持的一部分包含进来,但后来在c++ 0x草稿中被重新命名(N2992在2009年完成了),以供以后的版本使用。
You should not use <cstdatomic>
unless you are stuck with GCC 4.4 and happy to use an incomplete and buggy version of C++11 atomics. (I have no idea why Kubuntu's GCC 4.6 includes the header, it is not in the upstream GCC 4.6 releases, it must be an Ubuntu or Kubuntu or Linaro patch.)
您不应该使用
<atomic>
is the standard C++11 header that you can rely on for any reasonably conforming C++11 implementation.
<stdatomic.h>
is the C11 header, but the C++11 library is based on the C99 library, so does not include <stdatomic.h>
and does not provide a <cstdatomic>
corresponding to it.
< stdatomic。h>是C11的头,但是c++ 11库基于C99库,所以不包含
#1
8
<atomic>
is the C++ atomic operations library.
<cstdatomic>
is the C++ version of the C atomic operations library.
Both will give you e.g., std::atomic_char
but only the C++ version has std::atomic<T>
.
两者都将给出例如std::atomic_char,但只有c++版本具有std::atomic
As a general rule, C headers should be used in C++ by removing the .h
extension and prepending c
to the name: stdatomic.h
becomes cstdatomic
. That will include the C headers into the namespace std
.
一般来说,在c++中,应该通过删除.h扩展名和将C前置到名称:stdatomic来使用C标头。h变得cstdatomic。这将把C标头包含到名称空间std中。
Note also that stdatomic.h
(and cstdatomic
hence) is C11 and atomic
is C++11, which might explain the difference in compiler support.
还要注意stdatomic。h(因此是cstdatomic)是C11, atomic是c++ 11,这可能解释了编译器支持方面的差异。
#2
15
Both existing answers are wrong, and most comments too.
现有的答案都是错误的,大多数评论也是如此。
<cstdatomic>
is not a header defined in any standard.
It was defined in old C++0x drafts but is not in the final C++11 standard, only <atomic>
is. So it was included as part of GCC 4.4's experimental C++0x support, but then renamed for later releases when it got renamed in the C++0x drafts (which was done in 2009 by N2992).
它是在旧c++ 0x草稿中定义的,但不是在最终的c++ 11标准中,只有 <原子> 是。因此,它被作为GCC 4.4实验性的c++ 0x支持的一部分包含进来,但后来在c++ 0x草稿中被重新命名(N2992在2009年完成了),以供以后的版本使用。
You should not use <cstdatomic>
unless you are stuck with GCC 4.4 and happy to use an incomplete and buggy version of C++11 atomics. (I have no idea why Kubuntu's GCC 4.6 includes the header, it is not in the upstream GCC 4.6 releases, it must be an Ubuntu or Kubuntu or Linaro patch.)
您不应该使用
<atomic>
is the standard C++11 header that you can rely on for any reasonably conforming C++11 implementation.
<stdatomic.h>
is the C11 header, but the C++11 library is based on the C99 library, so does not include <stdatomic.h>
and does not provide a <cstdatomic>
corresponding to it.
< stdatomic。h>是C11的头,但是c++ 11库基于C99库,所以不包含