[Bug c++/60932] make stdatomic.h compatible with C++

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Apr 23 12:57:00 GMT 2014


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60932

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Sebastian Huber from comment #4)
> It is clear that you cannot use C++ header files from C.  So if you want to
> provide a library intended for C and C++ applications you must use C as the
> base line.  With this C++ incompatible <stdatomic.h> you cannot do this for
> applications requiring atomic operations.  So you are forced to provide two
> implementations.

Not true, I think this should work fine:

#ifdef __cplusplus
#include <atomic>
using namespace std;
#else
#include <stdatomic.h>
#endif

atomic<int> i;

int main()
{
  atomic_store(&i, 0);
  return atomic_load(&i);
}

The fact it doesn't looks like a problem with libstdc++'s <atomic> not
<stdatomic.h>

I don't think we want to support the _Atomic qualifier in C++.



More information about the Gcc-bugs mailing list