cosmopolitan
cosmopolitan copied to clipboard
atomic_load/atomic_compare_exchange_weak does not work on structures
The following code gives a compilation error using cosmocc (GCC) 11.2.0, while the code compiles without any error using GCC/Clang.
hello.c: In function ‘main’:
hello.c:11:3: error: operand type ‘_Atomic atomic_ant *’ {aka ‘_Atomic ant *’} is incompatible with argument 1 of ‘__atomic_load_n’
11 | ant ant2 = atomic_load(&ant1);
| ^~~
#include <stdatomic.h>
typedef struct ant {
int b;
} ant;
typedef _Atomic(ant) atomic_ant;
int main(int argc, char *argv[]) {
atomic_ant ant1 = { .b = 5 };
ant ant2 = atomic_load(&ant1);
return 0;
}