Search code examples
calgorithmheadermath.h

Understanding C Header Syntax


I'm new to C. I was traveling through math.h, looking for its mathematical algorithms, but encountered only this kind of lines:

_CRTIMP double __cdecl sin (double);
_CRTIMP double __cdecl cos (double);
...

Now, I couldn't find the algorithm itself. I know _CRTIMP is a kind of run-time library C uses, but I just can't figure out what the whole line means. Could you, please, explain?

Besides, I would like to know where these functions are defined at.


Solution

  • C headers typically contain only function prototype declarations, not definitions. Function prototypes specify what is called the "function signature": return value, arguments, and sometimes calling convention (when & where compilers support this). The function definitions are in a separate source file, that gets compiled separately from your own (including any headers your source file #include's). Definitions of library functions might be in C, they might also be in assembly, but that shouldn't matter to your code (only to your curiosity). But you probably don't compile those yourself anyway; instead, your development environment / operating system comes with a standard library (a binary object file) that contains many already-compiled functions. Your development environment simply links your code to that library.