0

Here is what I am wondering:

  • do the system header files (like iostream.h for C++ or stdio.h for C) only have function DECLARATIONS (ie prototypes) and not DEFINITIONS?

  • if so, where are these functions’ definitions? e.g. cout in C++, printf in C?

The attached picture suggests to me that the header files only have function prototypes, not definitions, and that the definitions are in the standard library, which the linker has access to. If this picture is accurate, where is the standard library? Is it a set of files on my system, or part of the compiler/linker?

Edit: I can’t attach an image...

Baran Karakus
  • 193
  • 1
  • 7
  • Usually, the compiler comes with libraries containing the implementations, like libc++ or libstdc++. Usually, you don't have to link explicitly, compiler uses them implicitly. Apart from, these do not really differ from any static library you build yourself. You should find the libraries in the installation directory of your compiler. – Aconcagua Oct 05 '19 at 15:35
  • To clarify, you’re saying the standard library is a part of the compiler, yes? – Baran Karakus Oct 05 '19 at 15:38
  • In that case I would assume the header files like stdio.h or iostream.h only have function declarations and not definitions? – Baran Karakus Oct 05 '19 at 15:38
  • 3
    Depends, if they are templates (unless fully specialised), the implementation must be contained in the header, compare https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file. – Aconcagua Oct 05 '19 at 15:40
  • Which system are you on? On my local system, there is `/usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so` (among others, having more than one compiler installed). – Aconcagua Oct 05 '19 at 15:47
  • Actually, you won't find the *definitions*, you will find object code, so already compiled code. If you want to get the definitions as uncompiled C++ code, you will have to peek into the sources for those libraries. With GCC or clang no problem, as open source, MSVC might be difficult to get. – Aconcagua Oct 05 '19 at 15:50
  • 2
    If there are library files, you will need to look at your compiler documentation to find out where they are - it will vary by compiler and OS, maybe even changing between versions. – Mark Ransom Oct 05 '19 at 15:53
  • 1
    Seems as if you can find sources for libstdc++ (used e. g. by GCC) [here](https://github.com/gcc-mirror/gcc/tree/master/libstdc%2B%2B-v3/include), or you clone the git repository directly from [GNU site](git://gcc.gnu.org/git/gcc.git) – Aconcagua Oct 05 '19 at 15:54

0 Answers0