A solution to the multiple inclusion problem
Richard O'Keefe
ok at cs.mu.oz.au
Fri Oct 27 23:49:14 AEST 1989
In article <2550110 at hpisod2.HP.COM>, decot at hpisod2.HP.COM (Dave Decot) writes:
> > Why does everybody feel compelled to reinvent this wheel?
> Because there's no STANDARD (**HINT**) way to do it that has any
> hope of efficiency!!
But we've been shown several. The simplest is the two-files-per-header
method:
your file foo.h foo1.h
#include "foo.h" #ifndef FOO_H /* whatever */
#define FOO_H 1
#include "foo1.h"
#endif
You can apply this technique even when foo1.h is a header file supplied
by someone else: foo.h gets rescanned every time but this is file
open + file close + reading four lines, and the #pragma once hack saves
you just the cost of reading three lines. Big saving, huh?
More information about the Comp.lang.c
mailing list