+ 3
Can we see the actual code of predefined function s in c language?
Such as sqrt, getch, sin, cosine, abs, atoi, atof,etc
4 Réponses
+ 2
How to open a header file
+ 2
"actual code"
I assume you're referring to the implementation of the standard library functions which their "declarations" (not implementations) are available in respective header files. For example, the declaration of `sqrt()` in `math.h` file is like
_CRTIMP double __cdecl sqrt (double);
Which means, the compiler only aware of the existence of `sqrt()` and it's the linker responsibility to find and link the `sqrt()`'s object code[1] to the client code before runtime.
[1] Since the standard library's `*.c` files (implementations) are all pre-compiled (as object code), the only way to inspect the underlying implementation (which is different in each implementation) is through available repositories that holding the standard libraries sources. Here[2], you will see the `sqrt()`'s implementation and here[3] you'd find `__ieee754_sqrt()`'s being called by `sqrt()`.
[2] https://github.com/bminor/glibc/blob/master/math/w_sqrt_compat.c
[3] https://github.com/bminor/glibc/blob/master/sysdeps/ieee754/dbl-64/e_sqrt.c
+ 1
You can, by opening the header file
+ 1
Just open the file, like a source code