views:

122

answers:

3

I will be very grateful, if somebody can actually explain what exactly my compiler does when I press button BUILD, and compiler begins to compile all my .h and .cpp files how exactly this process is going on(what do I have inside object file?), why do I ask such question? I'm trying to understand what does it mean "minimize compilation dependencies between files" from book of Meyers about 50 specific ways...(hope You know about this book),there he explains what does it mean Abstract Base Class and Handle Classes, as my lecturer explained me I don't need to include excessive .h files and thats all, any links about compilation process will be appreciated as well, thanks in advance for any help

A: 

The best way to understand how a compiler works is to first understand how an assembler works. There is a decent explanation here.

JackN
+4  A: 

When doing a full compile, the compiler will read each .cpp file in turn. For a given .cpp file it will then read every file referenced by a #include directive, recursively, compiling the code as it goes. When it compiles the next source file it will read the files referenced with #include in that source file.

When you make any changes and do a build, then if any of the files referenced by a #include directive from your .cpp file have changed then the .cpp file will be recompiled, as if the .cpp file itself has changed.

Unnecessary #include directives thus have two costs: firstly the compiler has to read and process more files when compiling, and secondly it increases the chances that your .cpp file will need recompiling even if nothing it actually uses has changed.

Anthony Williams
+1  A: 

See

http://computer.howstuffworks.com/c2.htm for a introduction and

http://www.tenouk.com/ModuleW.html for an in depth descirption

Additionally, some theoretic background can be found at http://en.wikipedia.org/wiki/Compiler

sum1stolemyname