C Style

T. William Wells bill at twwells.uucp
Thu Jan 12 00:06:48 AEST 1989


In article <2688 at ficc.uu.net> peter at ficc.uu.net (Peter da Silva) writes:
: I have been told that the following mechanism for handling nested includes
: is unreliable and/or unportable, but for the life of me I can't see how:
:
: graphics.h:
:       #ifndef GRAPHICS_H
:       #define GRAPHICS_H
:       ...
:       #endif
:
: windows.h:
:       ...
:       #ifndef GRAPHICS_H
:       #include GRAPHICS_H

(Presumably you mean #include "graphics.h".)

:       #endif
:       ...
:
: menus.h:
:       ...
:       #ifndef GRAPHICS_H
:       #include GRAPHICS_H
:       #endif
:       ...
:
: Now this allows a programmer to include windows.h and menus.h, without
: having to (a) know they need to include graphics.h, and (b) worry about
: graphics.h being included twice.
:
: What's wrong with this picture?

Not a thing. The company I work for does this routinely.  Our source
code is ported all over the place (70+ different systems for one
customer alone!) and we've never had a complaint about this.

Strictly speaking, the #ifndef's in the other include files aren't
necessary but they do save on the time needed to skip the useless
files.

---
Bill
{ uunet!proxftl | novavax } !twwells!bill



More information about the Comp.lang.c mailing list