The answer to your question simply lies in the fact that “it would be much more difficult to write a compiler if it weren’t” - the language specification says that it should be, but the reason for this wording in the language of the specification is that “it simplifies writing the compiler this way. " To some extent, it is also likely that in the old days compilers generated code “as they moved” and at first did not read all the code in the translation block (source file), and then processed it.
Remember that C and C ++ compilers are still used on machines that do not have huge amounts of memory and very fast processors. Thus, if you try to compile LARGE amounts of code on a machine with low bandwidth, then “we don’t want to read ALL the source first and then go to it”, this makes more sense than on a 16-gigabyte quad-core desktop machine. I expect that you immediately load all the source code for a fairly large project into memory (for example, all files in LLVM + Clang are about 450 MB, so they can easily fit into memory on a modern desktop / laptop).
Edit: It should be noted that “interpreted languages” such as PHP, JavaScript, and Basic generally do not have this requirement, but other compiled languages ​​are usually executed - for example, Pascal has a special forward keyword to tell the compiler that this function exists, but I will tell you what it contains later.
Both Pascal and C (and C ++, because they are based on C in this aspect) allow you to point to structures that are not yet complete. Just this simple “you don’t have all the information” means that the compiler must create the type information and then “come back and fix it” [obviously, only when necessary]. But this allows us to:
struct X { struct X* next; ... };
or in C ++:
struct X { X* next; ... };
Edit2: This blog post by Jan Gubicki, a GCC developer, explains some issues with "accessing all code simultaneously." Of course, most of us do not compile Firefox projects of a similar size, but large projects, when you have to deal with EVERYTHING from the code right away, really cause problems with "insufficient memory" even with modern machines, if developers don’t put "from time to time diet compiler. "
http://hubicka.blogspot.co.uk/2014/04/linktime-optimization-in-gcc-1-brief.html