* Headers including other headers?
@ 2002-02-23 9:23 Jim Blandy
2002-02-23 9:56 ` Andrew Cagney
0 siblings, 1 reply; 2+ messages in thread
From: Jim Blandy @ 2002-02-23 9:23 UTC (permalink / raw)
To: Andrew Cagney; +Cc: gdb
Suppose a header file in gdb/ contains code cannot be compiled without
definitions from other header files --- it uses typedefs, structures
in a way that requires their size, etc. Is it more proper for the
header file to #include the other headers it requires itself, or
should it be the responsibility of the .c file #including it to also
bring in its prerequisites?
In hopes that this doesn't start a really long thread of unsatisfying
disagreements: I personally think that this is not a matter of huge
consequence either way, but it's nicer to have a consistent pattern,
so having someone simply establish any reasonable guideline is more
important than the actual details of that guideline.
I'm not volunteering to convert our existing headers; I just want to
know what style is recommended for new header files.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Headers including other headers?
2002-02-23 9:23 Headers including other headers? Jim Blandy
@ 2002-02-23 9:56 ` Andrew Cagney
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Cagney @ 2002-02-23 9:56 UTC (permalink / raw)
To: Jim Blandy; +Cc: Andrew Cagney, gdb
The style guide says:
http://sources.redhat.com/gdb/onlinedocs/gdbint_13.html#SEC111
> All `.c' files should include `defs.h' first.
>
> All `.c' files should explicitly include the headers for any declarations they refer to. They should not rely on files being included indirectly.
>
> With the exception of the global definitions supplied by `defs.h', a header file should explictily include the header declaring any typedefs et.al. it refers to.
>
> extern declarations should never appear in .c files.
>
> All include files should be wrapped in:
>
>
>
> #ifndef INCLUDE_FILE_NAME_H
> #define INCLUDE_FILE_NAME_H
> header body
> #endif
along with:
http://sources.redhat.com/gdb/onlinedocs/gdbint_13.html#SEC107
> Declarations like `struct foo *' should be used in preference to declarations like `typedef struct foo { ... } *foo_ptr'.
(Daniel J, note clause #1 :-).
> Suppose a header file in gdb/ contains code cannot be compiled without
> definitions from other header files --- it uses typedefs, structures
> in a way that requires their size, etc. Is it more proper for the
> header file to #include the other headers it requires itself, or
> should it be the responsibility of the .c file #including it to also
> bring in its prerequisites?
> In hopes that this doesn't start a really long thread of unsatisfying
> disagreements: I personally think that this is not a matter of huge
> consequence either way, but it's nicer to have a consistent pattern,
> so having someone simply establish any reasonable guideline is more
> important than the actual details of that guideline.
>
> I'm not volunteering to convert our existing headers; I just want to
> know what style is recommended for new header files.
If you find you need to #include a system header file (since defs.h
doesn't include it) then consider re-structuring the code so that GDB
uses a host independant type - make the object opaque for instance.
Andrew
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-02-23 17:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-23 9:23 Headers including other headers? Jim Blandy
2002-02-23 9:56 ` Andrew Cagney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox