Re: header files

From: Francis Glassborow (francis_at_robinton.demon.co.uk)
Date: 04/05/04


Date: Mon, 5 Apr 2004 20:58:43 +0100

In message <c4s9o6$k0i$1@newsg3.svr.pol.co.uk>, mike ttoouli
<mttoouli@yahoo.com> writes
>hi jeffc, sorry I wasn't being very clear.
>
>It was never my intention to create one big file - lots separate files, each
>being used by one another. All the code could just be written in .h files,
>and used by other .h files by including them (#include "filename.h" - can
>this be done with cpp files?).
>
>This would lead to the problem of including the same header file in more
>than one place in a large program, but by enclosing the code in each header
>file using:
>
>#ifndef FILENAME_H
>#define FILENAME_H
>..code...
>#endif
>
>then this would ensure that the header file is added only the first time it
>is encountered in a program, as after that FILENAME_H is defined.

Then your program will have to consist of a single monolithic
translation unit. The job of header files is to mediate between a
program written as multiple TU + one or more libraries.

One mamoth disadvantage of the monolithic approach is that every change
anywhere requires complete recompilation.

>
>well i think that makes sense. I've implemented a fairly large program only
>using header files, and I couldn't really see the point of .cpp files at
>all.

Sorry, but I do not believe you (I am sure you think you have buyt a
fairly large program would consist of tens of thousands of lines of
code.) If you cannot see the point of .cpp files I suspect you do not
understand the basics of organising work the way C and C++ have been
designed for.

-- 
Francis Glassborow      ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


Relevant Pages

  • 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)
  • Preprocessor, nested files etc.
    ... I expected one big file but instead got one preprocessor file for each ... of the cpp files in the project. ... when I #define macros and put them at the beginning of the header file ... then those macro definitions don't seem to stick. ...
    (comp.lang.cpp)
  • Re: header files
    ... It was never my intention to create one big file - lots separate files, ... This would lead to the problem of including the same header file in more ... then this would ensure that the header file is added only the first time it ... and I couldn't really see the point of .cpp files at ...
    (alt.comp.lang.learn.c-cpp)
  • 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)
  • Re: code in header file?
    ... Marko Zagar wrote: ... >> is it ok to add code in the header file? ... > Aside from longer compile and link times (if you include that header in ... > other cpp files, the same code will be compiled again), I see no problem. ...
    (alt.comp.lang.learn.c-cpp)