Hi, I'm trying to understand preprocessor directives a little bit better. But first, I have some questions I would like sorted which I think are causing my failure to understand what Preprocessor Directives are...
The first question that I have is:
1.) if we are creating a program, why can there be more than one .cpp file attached to it? Aren't we writing code in one .cpp file in and around the 'main' function?
2.) ok so we have more than one .cpp file in our program (or in some we have just the one e.g. hello world) but essentially, when we run compile, it turns our C++ high level language code into machine code and spits out a .o or .obj file or something of the sort. How can we execute these .obj files? If we can't why not?
3.) Finally, we have the linking/linker whatever it is process. This process does what exactly? Haven't we already created the machine code during the compilation? Yes the name link suggests that we take the multiple .o/.obj files and morph them into 1 continuous file but I'm a little confused as why a .exe is what gets EXECTUTED by the processor whilst .obj and .o don't.
4.) It's said that C++ is quite a limited language in its raw form? How can it be so? Aren't libraries that we declare as Preprocessor Directives written in C++? OR is a library essentially a bunch of functions (which I know they are) which are written in the very basic raw C++ form which then you are then able to reuse i.e. not have to create from scratch every time you need to use one? So essentially a library is the first 'version' of object oriented code? Is another reason for using libraries in order to conserve space?
Finally 5.) When we link the .o/.obj files and create the .exe file, what actually happens? I'm guessing a program which does the linking process (either within an IDE or a 3rd party one) simply takes individual .o/.obj files and sticks them together one after the other? Or is this more conceptually what happens? So when it comes to INCLUDING various libraries or stating Preprocessor Directives, what ends up happening is that the linker essentially seeks the files where the library is stored, then copies the C++ code, compiles it into a .o/.obj form, then sticks it into ... where? Which .obj/.o file? The way I see it, all it's doing in this stage is essentially creating a machine code version of a function which one would write source code for and sticks it in some portion of some file which as I said, I'm not entirely sure where so that when the computer gets to a particular instruction, it knows exactly what to do.
Hence the space saving is occuring because this way, rather than having to copy every single conceivable function into the .obj/.o/.exe file so that if some function is called, the processor knows what to do, we only INCLUDE what is needed by the program? So essentially, #include is simply an instruction which the ?complier? or the ?linker? sees and then searches the libraries in some folder, finds the library and then copy pastes the functions within that library into our main.cpp file?