Re: typical practise for #include's



Roman Mashak wrote:
> Hello, All!
>
> I wonder are there any typical, common used practises to organize all
> #include's in the large/medium size project. Try to explain what I mean:
> suppose I have three tranlsation units in project and correspondent header's
> with functions declarations, typedefs and etc.:
>
> unit1.c, unit1.h
> unit2.c, unit2.h
> unit3.c, unit3.h
>
> In my opinion it would be very simple to make ONE big header, call it
> defs.h, which include in every unit's header file. That defs.h would include
> all important headers (suppose stdio.h, stdlib.h, string.h, errno.h so on)
> and also some macros, variables, types. It seems fine, except the issue that
> some of these headers might be useless in other translation units, though
> preprocessor will process it.
>
> Hopefully my explanation is comprehensible :)
>
> With best regards, Roman Mashak. E-mail: mrv@xxxxxxxx
>
>

This seems like scheme Microsoft is using by default in their compilers.
Only they call your "defs.h" as "stdafx.h".

This technique is very effective for generating precompiled headers,
because compiler parses all those headers only once for entire project.

Depends if your compiler supports this method or not. But generally do
not be too concerned with including few thousand lines <stdio.h>
somewhere where it is not needed because time for compilation of file
that small is negligent (few milliseconds on modern machines).

The problem I would like to point out for you is that you get your
global namespace and macro namespace polluted much more this way. Think
how many C programmers use common word macros in place of constants and
inline functions. Or all those IN and OUT macros, Abort or GetTime function.
.



Relevant Pages

  • Re: Using GDI+ in C++
    ... out how to modify library or API headers. ... that purpose, today, the compiler has a few options that ... The reason for it can be seen by looking at the output of: ... the definitions of the symbols mentioned in the complaints. ...
    (microsoft.public.vc.language)
  • Re: Thoughts on file organisation
    ... also note that it is a common misconception (especially among moderate-use languages) for the users to somehow think that their language rules the world. ... whether I maintain seperate public and private headers, depends on the specifics of what I am writing. ...
    (comp.lang.c)
  • Re: precompiled headers question
    ... All my source files are not in the same folder. ... which contains headers and sources of publishing functionality. ... That is because the compiler will look for the PCH instead of trying to load ... extern int MyFunction; ...
    (microsoft.public.dotnet.languages.vc)
  • Re: C and other programming languages
    ... language of choice, otherwise I wouldn't be using it in the first place. ... The main problem is that headers are not ... useless because they are often highly compiler specific. ... So setting the size of a string, ...
    (comp.lang.misc)
  • Re: PROS/CONS: #define BEGIN {
    ... It could cause the compiler to assume that subsequent code ... > detect and report a syntax error, but it could report any number of ... check for syntax errors in the headers. ... gcc usually dies with a parse error. ...
    (comp.lang.c)