Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ed286f9

Browse files
CODING_STANDARDS.md: add rules for #include directives
This is my proposal for keeping header dependencies small and correct. See php#10220 for the discussion.
1 parent 889dba4 commit ed286f9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎CODING_STANDARDS.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,25 @@ rewritten to comply with these rules.
263263
codebase but should not be refactored, unless larger refactoring around that
264264
code is taking place.
265265

266+
## C Headers
267+
268+
1. Include only the headers (`*.h`) that are really needed. Consider
269+
using [iwyu](https://include-what-you-use.org/).
270+
271+
1. Use forward declarations to eliminate `#include` directives if
272+
possible.
273+
274+
1. If some headers are needed only in some build configurations,
275+
enclose them in the same `#if` that also guards the use of its
276+
definitions.
277+
278+
1. Each source file (`*.c`) should include its own header file first
279+
to ensure that the header's `#includes` are complete.
280+
281+
1. Header inclusions are ordered this way: its own header first, then
282+
PHP headers, then third-party library headers, then system headers
283+
(e.g. libc, POSIX).
284+
266285
## Testing
267286
268287
1. Extensions should be well tested using `*.phpt` tests. Read more at

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /