-3

I want to learn the source code of floor() in c Function library, so I use the Vs quick lookup definition function to find in VS, and then

I find that _Check_return_ _ACRTIMP double __cdecl floor(_In_ double _X); statement。

I don't know what to do next.enter image description here

Because there seems to be only a macro definition, no function definition。 Is it that I should not use the IDE to view the source code, I am a newbie。

Jeff_
  • 9
  • 3
  • 3
    The standard libraries are usually highly optimized and because of that the code is convoluted and very hard to read and understand. If you want to learn the principals behind the functions, try to find an idealized and clear implementation that shows the principles instead. – Some programmer dude Apr 03 '19 at 07:42
  • 1
    Compare [Where are the VS2015 UCRT Source files?](https://stackoverflow.com/questions/49048673/where-are-the-vs2015-ucrt-source-files) – Martin R Apr 03 '19 at 07:42
  • 4
    As for your problem, create a program that uses the function. Make a debug build, and use the debugger to step into the function. For Visual Studio that should take you to the source (if it's installed, which it usually is). – Some programmer dude Apr 03 '19 at 07:43
  • @Jeff: you need to understand that a compiler and an IDE are two very different things. – Basile Starynkevitch Apr 03 '19 at 08:08

2 Answers2

2

Most library functions are visible to your project just as prototypes, as they have been already compiled into a static (or dynamic) library. As far as functionality is concerned, the compiler could ship without those sources, as they are not necessary to compile your program. It's pretty much the same e.g. for OS APIs: you invoke them all the time, but you don't have the Windows sources.

On the other hand, Visual C++ traditionally shipped with the sources of (most of) its C runtime to aid debugging; they are usually found somewhere under your VC++ installation directory.

edit better indications in this answer; thanks @Martin R for digging it out

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
  • Thank you brother, I thought I could use the IDE directly to save the trouble in the root directory. It seems that I need to understand the relationship between IDE and source code, how to implement the compilation process. – Jeff_ Apr 03 '19 at 08:01
2

In general, for C, no.

C code can be shipped in pre-compiled form, when you get:

  • A header file (mylibrary.h) that provides declarations of contents of a particular module of code.
  • A library (mylibrary.lib, mylibrary.dll, mylibrary.so and so on, depending on the exact type of library and the platform), this contains the code and data that are needed for the module.

These two files are enough; the compiler reads the header when you #include it in your code, and the linker "glues in" the necessary code and data from the library.

Note that there is no source code available.

The floor() function is part of the C runtime library and shipped with the compiler implementation; I'm not sure whether Microsoft provides the source for theirs. Of course there are open source implementations, here is the code from the "musl" implementation of the C standard library, for instance.

unwind
  • 391,730
  • 64
  • 469
  • 606