Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "atomic" and "cstdatomic"?

Tags:

c++

c++11

atomic

can someone please clarify the difference between the include options #include <atomic> and #inlucde <cstdatomic>?

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.

  • compiler on Debian: version 4.7.2 (Debian 4.7.2-4)

  • compiler on Kubuntu: version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

like image 775
baam Avatar asked Jun 19 '13 07:06

baam


1 Answers

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).

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.

like image 144
Jonathan Wakely Avatar answered Nov 07 '22 05:11

Jonathan Wakely