A solution to the multiple inclusion problem
Doug Ingraham
dpi at loft386.UUCP
Thu Oct 26 03:23:11 AEST 1989
In article <4643 at buengc.BU.EDU>, bph at buengc.BU.EDU (Blair P. Houghton) writes:
> How about ( in <foo.h>):
>
> #pragma Never_Again
>
> Which tells the BlairTech/ANSI1.0 compiler that when it hits
> a #include to read this file again, it should just ignore it.
>
> --Blair
In GNU gcc this is already implemented as a pragma.
#pragma once
Seems like an obvious enough thing that every compiler vendor
will eventually have their own incompatible version of this
construct.
I have put both constructs in my ANSI compatible header files so
that they look like this:
#pragma once
#ifndef _STRING_H
#define _STRING_H
/* REST OF HEADER */
#endif
In this way if compiled on a compiler that doesn't recognize the once
pragma, it still has the desired effect.
--
Doug Ingraham (SysAdmin)
Lofty Pursuits (Public Access for Rapid City SD USA)
uunet!loft386!dpi
More information about the Comp.lang.c
mailing list