Re: Rob Pike's simple Include rule
From: Thomas Matthews (Thomas_MatthewsSpitsOnSpamBots_at_sbcglobal.net)
Date: 04/23/04
- Next message: Alberto Giménez: "Re: Error handling"
- Previous message: Thomas Matthews: "Re: Valid operations on pointers in C"
- In reply to: Neil Cerutti: "Rob Pike's simple Include rule"
- Next in thread: Alan Balmer: "Re: Rob Pike's simple Include rule"
- Reply: Alan Balmer: "Re: Rob Pike's simple Include rule"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 23 Apr 2004 16:19:41 GMT
Neil Cerutti wrote:
> In Rob Pike's style guide he urges the following:
>
> Simple rule: include files should never include include
> files. If instead they state (in comments or implicitly)
> what files they need to have included first, the problem of
> deciding which files to include is pushed to the user
> (programmer) but in a way that's easy to handle and that,
> by construction, avoids multiple inclusions.
>
> I was startled by this guideline, since it's not what I think of
> as the usual practice, i.e., brute-force idempotency through
> header guards in the headers.
In our shop we have the types
UINT8, UINT16, UINT32
defined a unsigned integers with the given bitwidth.
We have one file, let's say types.h, which defines those types
for various platforms.
So if I write a function:
UINT8 Public_Function(UINT16 variable)
{
/* ... */
}
and I want to make it public, I put it into a header file
my_functions.h:
UINT8 Public_Function(UINT16 variable);
Now, since it uses the UINT8 and UINT16 in the declaration,
those identifiers must be resolved before this function
declaration.
According to the style guide, a programmer must include
the types.h file before the my_functions.h file.
If the my_functions.h file has the statements:
#ifndef UINT8
#include "types.h"
#endif
before the function declaration, the user only has to
worry about including one function. The header file
takes care of its own declaration issues.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
- Next message: Alberto Giménez: "Re: Error handling"
- Previous message: Thomas Matthews: "Re: Valid operations on pointers in C"
- In reply to: Neil Cerutti: "Rob Pike's simple Include rule"
- Next in thread: Alan Balmer: "Re: Rob Pike's simple Include rule"
- Reply: Alan Balmer: "Re: Rob Pike's simple Include rule"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|