Re: Preprocessor, nested files etc.

From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 08/13/04


Date: Fri, 13 Aug 2004 10:07:43 +0200

Florian wrote:
>
> then those macro definitions don't seem to stick. When the next cpp files is
> being processed, the header file is being included again - even though the
> macro was previously defined
>
> Is this normal, and where am I getting confused?

Each source code file (each *.cpp) is compiled independently of all others.
That's the way things work in C++.
And of course it makes sense. Your project consists of 10 files. The project
I am involved in, consists of more then 400 files. Consider I make a change
in one of them and the compiler is going to recompile everything (sometimes
we have to do this, it takes around 2 hours for a complete recompile).

When the compiler compiles a *.cpp file, it starts in a fresh state. Nothing
it has learned by compiling a previous source code file remains. Which is
a good thing, because it means it can compile a collection of *.cpp files
in any order it likes. If you make a change in one of them, only this file
needs to be recompiled and the linker will form a new executable from the
results of all the copilation steps (they are called 'object files' or 'machine
code files')

-- 
Karl Heinz Buchegger
kbuchegg@gascad.at


Relevant Pages

  • Re: classes, strings, learning in VS.NET
    ... The class implementation goes into the .cpp file. ... for C++ compiler. ... .cpp files is completely independent from each other. ... include file is included twice within the same translation unit. ...
    (comp.lang.cpp)
  • Re: How protect source code in template library?
    ... > prevent others from getting .cpp files. ... To instantiate template code for new data types, ... the compiler does need to see the template source code (which ... (while the way to call C-style functions is pretty much ...
    (comp.lang.cpp)
  • Re: newbie question
    ... You need to do the include anywhere you want to reference the variable, ... front of the declaration so the compiler knows it's created elsewhere. ... I have a source file called complx.cpp. ... Both .cpp files are in my project. ...
    (microsoft.public.vc.ide_general)
  • Re: Internal Complier Error in VC++ 1.52
    ... You may have hit some brick wall in the compiler. ... I am working on an existing code base where the no of lines is around 100,000, spread across different header and cpp files. ... when i was trying to add a new function declaration for an existing class in a header file and function implementation in the .cpp file i am getting an error as given below ... CL returned error code 2. ...
    (microsoft.public.vc.mfc)