The C17 standard deprecates ATOMIC_VAR_INIT
from stdatomic.h
, meaning it still supports it but would rather it not be used. What is the correct non-deprecated way of initializing atomics in C17?
Same as non-atomic types:
atomic_int foo = 42;
Or something new?
C17 makes it ok to initialize atomics using the usual explicit initialization:
C17 literally just dropped the two words "using ATOMIC_VAR_INIT" from the sentence in 7.17.2.1.
Based on that document, section DR 454, using the macro makes it impossible to know in which state is the variable.
But using the normal assignment is also undetermined, as shown bellow.
To put your variable in a known state, you have either to use
static
or theatomic_init
function.But that's the only information I could find.