A question on C programming style

Lars Wirzenius wirzenius at cc.helsinki.fi
Tue Apr 16 01:29:53 AEST 1991


In article <189 at bria.UUCP>, mike at bria.UUCP (Michael Stefanik) writes:
> In an article, wirzenius at cc.helsinki.fi (Lars Wirzenius) writes:
> | [ ... that I don't prefer nested inclusions -- lw ]
> 
> Actually, if the include files are written correctly, very *little* time
> is wasted and no errors are produced.  It's a simple matter of wrapping
> the include file in:
> [ #ifndef SYM / #define SYM / ... / #endif ]

Very much time can be wasted, if the compiler has to process, say,
stdio.h (or another large header) multiple times. I can easily find
several of my own programs, for which nested includes like this could
cause some headers to be included about 10 or 15 times. Of course, if
you're the only user on a 100 GIPS computer, that doesn't really affect
compile times, but on my humble PC the time escalates very quickly.

Furthermore, not all system headers are protected by the #ifndef/#define
construction, and not everybody can change them, so the possibility for
errors due to multiple inclusion will always be there, if the program is
ever going to be ported.

> Personally, I have found that nested includes are both convenient, and
> make a great deal of sense.

I agree, in theory, but I have great reservations in practice.
-- 
Lars Wirzenius    wirzenius at cc.helsinki.fi



More information about the Comp.lang.c mailing list