On 4/3/2011 10:14 PM, David Sudolcan wrote:
> Well I'll be... I checked 'The C Standard', and you are indeed
> correct. Just goes to show that you can learn something new every
> day. Thanks for pointing that out. And you're right about me seeing
> that in other folks code. I'll have to share that at work, and change
> the way we do our include file guards.
>
> About including include files in include files, our coding standard
> says not to do that. Nor sure why. But, I've seen it both ways. Is
> there any drawbacks to including include files in include files?
In the Days of Yore when machines had maybe 32-64KB of memory
and a hard upper limit of about 16 simultaneous open files, a rule
that said "No header may #include another" was useful. Such a rule
could make the difference between a file that compiled and a file
that broke the compiler.
Nowadays I cannot see that such a rule makes sense. In fact,
I think it makes anti-sense: Instead of telling the programmer
"You must #include foo.h to use the fooRoutines()," you have to
say "You must #include foo.h, and before that you must #include
bar.h and baz.h, and before baz.h you must #include gorp.h and
<string.h>, and ..." That is, the rule lightens the burden on
the computer (a little) and increases the burden on the programmer
(a lot). When computers were small and slow and CPU cycles were
scarce and expensive and programmer time was cheap, this shift of
responsibility was perhaps justifiable. Today, when we've got more
memory and more cycles than we know what to do with -- and when
engineering time is the single biggest cost in producing software! --
the antiquated rule is hard to defend.
(Data point: My current employer has exactly the opposite rule.
Every header is *required* to #include everything it needs. We are
officially encouraged to see to it that every header appears as the
very first #include in at least one compilation, to ensure that it
has omitted nothing essential. I do not claim that my employer does
everything right at all times, but the company has been fairly
successful by most measures, and the coding tactics followed by
successful companies are perhaps worthy of your consideration.)
But if your company is stuck in the 1970's, that's life. If you
can't change the rules, you must either obey them or find somewhere
else to work.
--
Eric Sosman
d