Consider this simple code:
#include <iostream>
#include <atomic>
void add(std::atomic<double> & a, double c)
{
std::atomic_fetch_add(&a, c);
}
int main()
{
std::atomic<double> a;
a.store(0);
std::cout << a.load() << std::endl;
add(a, 5.0);
std::cout << a.load() << std::endl;
std::cin.get();
}
Compiling it will result in:
error LNK2019: unresolved external symbol "double __cdecl std::atomic_fetch_add(struct std::atomic *,double)" (??$atomic_fetch_add@N@std@@YANPAU?$atomic@N@0@N@Z) referenced in function "void __cdecl add(struct std::atomic &,double)" (?add@@YAXAAU?$atomic@N@std@@N@Z)
According to this, atomic_fetch_add
is defined in <atomic>
, so what is happening?