Open Quuxplusone opened 9 years ago
Attached at.c
(900 bytes, text/plain): c11 atomics test program
All your member accesses on the atomic struct object have undefined behavior, per C11 6.5.2.3/5. We should probably accept them with a warning.
Correct, but undefined behavior in Standardese does not mean "Verboten". It
only means that the Standard does not provide a normative behavior.
GCC allows access to atomic members without warning, even with -pedantic:
/usr/bin/gcc -m64 -O0 -std=c11 -pedantic -Wall -c at.c -o at.o
at.c: In function 'main':
at.c:16:24: warning: unused variable 'TP' [-Wunused-variable]
_Atomic struct Test *TP = ATOMIC_VAR_INIT(NULL);
I believe GCC's implementation is a better approach, as it goes beyond the
minimum requirement of the Standard. It is less error-prone for developers,
and it avoids unnecessary copying between an atomic datum and a non-atomic
equivalent.
Take. I'm working on this, and I'll submit a codereview soon.
at.c
(900 bytes, text/plain)