cosmopolitan icon indicating copy to clipboard operation
cosmopolitan copied to clipboard

atomic_load/atomic_compare_exchange_weak does not work on structures

Open farkasmark opened this issue 7 months ago • 0 comments

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;
}

farkasmark avatar Jan 18 '24 14:01 farkasmark