473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

typical practise for #include's

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: mr*@tusur.ru
Nov 26 '05 #1
2 1571
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 :)


I am not sure whether this is topical round here.

Depending on your build system, your scheme can create
unnecessary compile dependencies -- every time one of the
headers included in defs.h is changed, all translation units
directly or indirectly including defs.h are considered "dirty"
and need to be recompiled; if you have medium size project (I
think of "in the range from 50,000 through 500,000 LoC") or
larger, then this may increase turnaround times to the point
where they become unsufferable even with shared build systems.

Apart from that, the individual compile times may be increased
if literally hundreds of unnecessary header files are part of
every translation unit.

However, this also depends on the structure of your project.

If you have many similar modules, comparable to implementations
of "child classes" (yes, there is no such thing in C but the
analogy is easier than describing everything around it), then
it may make sense to create one central header for _internal_
use of these modules i.e. to be included only directly in
translation units.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 26 '05 #2
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: mr*@tusur.ru


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.
Nov 26 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Carsten Fuchs | last post by:
Hello all, what please is the recommended (most future-safe, standard-compliant etc.) practise for exception specifications? I did some googling, and the trend seemed to be "don't use...
8
by: me | last post by:
The subject line says it all really. Any figures for the size of a typical JS interpreter?
10
by: Barry Morris | last post by:
Hi I am a php newbie although I have been a programmer for years, this can be dangerous because all the languages I know use = as equal comparison so it took me a long time to debug if ($STRING...
3
by: Rabbit | last post by:
I would like to know the common practise for the captioned subject Currently if create a Web Setup Project to deploy my ASP.net 2.0 solution, it will include all my source code, as my target...
2
by: bonk | last post by:
I have come across the need to distinguish between the creation of a deep and a shallow copy and with great interest I have read this article: ...
0
by: sri5739 | last post by:
Hi All, Could anyone please let me know how the best way to prepare for MCAD certifications for .net and whr can i get the practise papers and the questions for it. This will really help me ..Thanx...
0
by: sri5739 | last post by:
Hi All, Can anyone help in getting me the .net MCAD practise exams link and practise question papers .. this will really help me .. thanks a lot in advance
12
by: Slaunger | last post by:
Hi, I am new here and relatively new to Python, so be gentle: Is there a recommended generic implementation of __repr__ for objects equal by value to assure that eval(repr(x)) == x independet...
12
by: Muzammil | last post by:
i want good practice over recursion. can any one give me links for recursion questions site.?? or question.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.