1

I want to know , exactly how C predefined library functions like Prinf() ,scanf(),sin(x),abs() etc works . How they are defined and where is these functions body resides.

If I right click on these functions and select view definition in visual studio, it shows like this (for printf) int __cdecl printf(_In_z_ _Printf_format_string_ const char * _Format, ...);

How can I see the inner part of these functions ?

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
rishi
  • 653
  • 7
  • 10

1 Answers1

1

If your implementation ships with (or otherwise makes available) the source code for its runtime library, that's where you would find it.

You should first ask yourself whether that's necessary. The whole point of the ISO standard is to ensure every implementation is the same abstract machine, regardless of the underlying code.

That means you should generally just code to the standard without worrying whether, for example, qsort is implemented as a quick sort, merge sort or even, should it be not too concerned with performance, a bubble sort or bogosort.

Just be aware that it will follow the rules as laid out in the standard.


If you still want to examine the source for the library, something like gcc will use glibc (available here) and Visual C++ source code ships with the product as well. On my version (VS 2013), it's in C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\crt\src.

For example, since you expressed an interest in one of your comments about the abs() function, here's the VC++ variant from abs.c in that directory listed above:

int __cdecl abs (int number) {
    return (number >= 0 ? number : -number);
}

There's not much there that's surprising but something like output.c, which provides the common code for all the printf-style functions, clocks in at about two and a half thousand lines.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953