- The function name g_atomic_int_compare_and_exchange_full is in parentheses. What’s the significance of this?
Putting a function name in brackets avoids any macro expansion in case there is a function like macro with the same name.
That means, g_atomic_int_compare_and_exchange_full(...)
will use the macro while (g_atomic_int_compare_and_exchange_full)(...)
will use the function.
Why is this used?
You cannot assign a macro to a function pointer. In that case you can provide the definition as you saw it and then you can use
ptr = g_atomic_int_compare_and_exchange_full;
to use the function instead of the macro.
- The function’s body apparently consists of nothing but a call to the function itself so this will run forever and result in stack overflow (pun intended).
If you look into the associated header gatomic.h
you will see that such a macro is indeed defined. And in the function body, no brackets are used around the function name. That means, the macro is used and it is not an infinite recursion.