The standard states in 7.17.5.1 that atomic_is_lock_free has to be called with *a pointer to* the object in dispute.
So, except I am terribly mistaken, if the object is a pointer, one has to pass a pointer to a pointer.
But in the following test code one gets e. g.:
error #2141: Type error in argument 1 to 'atomic_is_lock_free'; '_Atomic float * *' is invalid.
Am I missing or misunderstanding something?
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
_Atomic float var_float;
_Atomic double var_double;
_Atomic long double var_long_double;
_Atomic float* p_var_float;
_Atomic double* p_var_double;
_Atomic long double* p_var_long_double;
atomic_init(&var_float, 42.0);
atomic_init(&var_double, 4711.1);
atomic_init(&var_long_double, 1000000.12);
atomic_init(&p_var_float, &var_float);
atomic_init(&p_var_double, &var_double);
atomic_init(&p_var_long_double, &var_long_double);
printf("\"_Atomic float var_float\" is %slock-free.\n", atomic_is_lock_free(& var_float) ? "" : "not ");
printf("\"_Atomic double var_double\" is %slock-free.\n", atomic_is_lock_free(& var_double) ? "" : "not ");
printf("\"_Atomic long double var_long_double\" is %slock-free.\n", atomic_is_lock_free(& var_long_double) ? "" : "not ");
printf("\"_Atomic float* p_var_float\" is %slock-free.\n", atomic_is_lock_free(&p_var_float) ? "" : "not ");
printf("\"_Atomic double* p_var_double\" is %slock-free.\n", atomic_is_lock_free(&p_var_double) ? "" : "not ");
printf("\"_Atomic long double* p_var_long_double\" is %slock-free.\n", atomic_is_lock_free(&p_var_long_double) ? "" : "not ");
exit(EXIT_SUCCESS);
}
Werner (on version 12.00)
As far as I understand, the pointed-to object must be atomic so float * _Atomic or _Atomic float * _Atomic but not _Atomic float *.
FWIW, a recent version of LLVM seems to agree about the errors (and IMHO the C11/C17/C2X standard could be a little clearer about atomic types).
Yeah, of course you are absolutely right! My mistake is blatant.
I should go back to 101 "Pointers for the Rookie" ...
I apologize for bothering you and the community with my silly mistakes.
Thanks for your immediate response.
Werner
No problem! (I did pretty much the same mistake some years ago...)