What is the c-style atomic free function like std::atomic_is_lock_free for?

Viewed 95

I understand that std::atomic_is_lock_free is c-style free function corresponding to std::atomic<T>::is_lock_free.

But the parameter of this function is like std::atomic_is_lock_free(const std::atomic<T>*). The std::atomic<T> is not c-style syntax so std::atomic_is_lock_free can't be used in c files anyway.

So why is this c-style free function introduced? What is the usage of this?

Edit:
Below is explanation from C++ Concurrency in Action.

The free functions are designed to be C-compatible, so they use pointers rather than references in all cases. For example......

It says free function is for C-compatibility. But I can't think of a good example.

1 Answers

There does not seem to be any difference, as both functions need an actual object according to the draft language which even gives the exact same description for both.

This seems to be a holdover from before the requirement "the result of the lock-free query is the same for all atomic objects of the same type"... given that requirement it would be useful to be able to query a type without having any object instance.

Related