Search code examples
c++cunixsystems-programming

where can i find the header of __sync_add_and_fetch


can any one tell me where can I find the header for __sync_add_and_fetch built in function
with out header how could we able to compile the code .


Solution

  • It is a built-in function, meaning the compiler KNOWS this function, and it doesn't have (to have) a header file.

    In clang, it is part of Builtins.def here: https://github.com/llvm-mirror/clang/blob/master/include/clang/Basic/Builtins.def#L524

    and codegen here: https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGBuiltin.cpp#L1204

    Other compilers will have some similar concepts in declaring "builtin functions".

    Of course, not all compilers support atomic builtins, so if you are seeing an error saying "__sync_add_and_fetch is not a function", it may be because the compiler doesn't have that function - it may be called something else in that compiler, or it may simply not exist, depending on what compiler it is.