Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Concerning the necessity of include guards
Date: Mon, 24 Feb 2020 21:17:48 -0800
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <8636azb5z7.fsf@linuxsc.com>
References: <20200224220814.34562e1774fd4d2c65f171a0@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="736228d0aa4bff80edfe6f310ec1eb3b"; logging-data="18257"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8Hv2nEHTXOVMmj3+KlKIxpEQxoDbQCqY="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:pz8eOKHflkWO+/Q5S3si4quqPS4= sha1:/kcbkyeI5B4Cl/3Wtm6NWxVS6Fw=
Xref: csiph.com comp.lang.c:150214
Anton Shepelev writes:
> A reviewer has recently declared it a fault in my library
> that its .h file does not use an include guard, whereas I
> deliberately decided not to use one, because the library
> exports only functions, but no types. Its header file is
> therefore designed for inclusion into .c files, but not into
> other .h files.
>
> What is your opinion? Is it good practice to wrap each and
> every header file in an include guard?
I think my position would be, unless there is a compelling
reason not to have an include guard, it's better to put
one in. Otherwise people will spend time wondering why
it was left off, and checking to be sure it really isn't
needed. By far the vast majority of header files need
include guards, so leaving them off should be done only
when circumstances positively warrant that for some reason.
Alternatively, you could name the header file "red-herring.h".