Preprocessor, nested files etc.

From: Florian (wizard_oz_at_gmxREMOVEUPPERCASE.net)
Date: 08/13/04


Date: Thu, 12 Aug 2004 22:17:26 GMT

Hi,

I'm hoping that someone can point me into the right direction here. I'm
trying to gain a bit of a better understanding on how the preprocessor
works - something that seems like a simple topic! I just keep running into
problems (Windows platform) because files are included in the wrong order,
one include file messes up the other one etc.. I think I need to brush up on
some basics here.

In this example project, I have several cpp files (~10) that all pretty much
include one common header file. In Visual Studio I turned the option on to
actually generate those pre-processed files - so that I could see what's
actually going on behind the scenes.

Well, I expected one big file but instead got one preprocessor file for each
of the cpp files in the project. OK, I suppose that this makes sense. One of
the things however I'm constantly trying to do is to prevent header files
from being included more than once - do I not need to worry about this when
it's included from different cpp files?

Also, when I #define macros and put them at the beginning of the header file
like

#ifndef HEADERFILE1_H
#define HEADERFILE1_H

...
..
#endif

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?

Thanks!
Flo.



Relevant Pages

  • Re: Where to include header files / A question of style?
    ... If a header file happens to be included twice, ... The preprocessor will skip over the entire ... "guard macro". ...
    (comp.lang.cpp)
  • Re: forms implementation should be in .cpp not .hpp file
    ... Why VS2008 doesn't create .cpp files when creating new form using ... file not in the header file. ... deliver service pack like compatibility for WindowsForms. ... Stop jumping saying "developers, developers, developers" and ...
    (microsoft.public.vc.ide_general)
  • Re: #ifdef
    ... It may be defined by the user, or somewhere in a header file, ... out of a larger context such as the OS source code ... C code after preprocessing but before compiling. ... in tracking down issues with preprocessor symbols. ...
    (comp.lang.c)
  • RE: rs232!
    ... the CSerialWnd.h path in the C++ preprocessor options." ... Where is the CSerialWnd class code? ... fatal error C1083: Cannot open include file: 'CSerialWnd.h': No such file or ... Up to now all I am used to is including windows.h and some odd header file ...
    (microsoft.public.vc.language)
  • Re: Howto check value of constants in a macro
    ... Oooh, that's clever! ... integer values and constant expressions, ... functional C preprocessor, just a program that produces C code as its ... header file that's then #included by your C source files. ...
    (comp.lang.c)