i'm trying use atomics in c on freebsd 10.1 release clang 3.6.1, when try compile program using atomic_flag_init on atomic_flag variable in struct error: expected expression.
here program trying compile.
#include <stdio.h> #include <stdatomic.h> struct map { atomic_flag flag; }; int main(void) { struct map *m = malloc(sizeof(struct map)); m->flag = atomic_flag_init; free(m); return 0; } i can use atomic_flag outside of structs in example below not in structs, how use atomic variables in c structs?
#include <stdio.h> #include <stdatomic.h> int main(void) { atomic_flag flag = atomic_flag_init; return 0; }
atomic_flag doesn't have value can assign or read from, internal state.
the way interact atomic_flag 2 functions (or 4 if count _explicit versions) defined it. case when got object through malloc flag in "indeterminate state" (7.17.8 p4 of c11). can put known state applying 1 of 2 functions, use atomic_flag_clear set "clear" state, or use atomic_flag_test_and_set set "set" state.
using atomic_flag_clear right after allocation malloc equivalent initialization of variable atomic_flag_init.
Comments
Post a Comment