What is the difference between atomic and cstdatomic?

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

I assume that he is not there because his behavior is the same?

I ask about this because on my debian system I only have an atomic system and on my kubuntu system I have cstdatomic.

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

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

+7
source share
2 answers

<atomic> is a C ++ atom operations library.

<cstdatomic> is a C ++ version of the C atom operations library.

Both will give you, for example, std::atomic_char , but only the C ++ version has std::atomic<T> .

Typically, C headers should be used in C ++ by removing the .h extension and adding c to the name: stdatomic.h becomes cstdatomic . This will include the C headers in the std .

Note also that stdatomic.h (and cstdatomic therefore) is C11 and atomic is C ++ 11, which may explain the difference in compiler support.

+8
source

Both existing answers are incorrect, and most comments too.

<cstdatomic> not a header defined in any standard.

It was defined in old C ++ 0x drafts, but not in the final C ++ 11 standard, only <atomic> is. Therefore, it was included as part of the experimental support for C ++ 0x GCC 4.4, but was then renamed for subsequent releases when it was renamed to C ++ 0x drafts (which was done in 2009, N2992 ).

You should not use <cstdatomic> if you are not stuck with GCC 4.4 and enjoy using the incomplete and buggy version of C ++ 11 atomicity. (I have no idea why Kubuntu GCC 4.6 includes a header, it is not in upstream versions of GCC 4.6 It must be a Ubuntu or Kubuntu or Linaro patch.)

<atomic> is the standard C ++ 11 header you can rely on for any reasonably appropriate C ++ 11 implementation.

<stdatomic.h> is the title of C11, but the C ++ 11 library is based on the C99 library, therefore it does not include <stdatomic.h> and does not match its corresponding <cstdatomic> .

+15
source

All Articles