Confirmed users
1,345
edits
Nnethercote (talk | contribs) |
Nnethercote (talk | contribs) |
||
| Line 219: | Line 219: | ||
* Use size_t for unsigned number of bytes variables, ptrdiff_t for signed pointer subtraction results. In particular, do not use uintN, which is just shorthand for unsigned int, and so may not be big enough. | * Use size_t for unsigned number of bytes variables, ptrdiff_t for signed pointer subtraction results. In particular, do not use uintN, which is just shorthand for unsigned int, and so may not be big enough. | ||
= | = Header files = | ||
== #ifndef wrappers == | |||
Use this exact form for #ifndef wrappers in header files: | |||
#ifndef <guard> | |||
#define <guard> | |||
... | |||
#endif // <guard> | |||
GCC and clang recognize this idiom and avoid re-reading headers that use it. Don't put any code before the #ifndef or after the #endif, and don't put anything else in the #ifndef, otherwise the optimization will be thwarted and the file will be multiply-included. (Check with the -H option if you want to be sure.) | |||
Include guards should be named by determining the fully-qualified include path, | |||
then substituting _ for / and . in it, and finally appending a trailing _. For | |||
example, "vm/Stack.h" becomes vm_Stack_h_. | |||
== #include paths == | |||
#include statements should use a fully-qualified (within SpiderMonkey) path, even if it's not necessary. For example, this: | |||
#include "vm/Stack.h" | |||
not: | |||
#include "Stack.h" | |||
This keeps things consistent and helps with the ordering. | |||
== #include ordering == | |||
The following order is used for includes: the module's .h (this ensures it includes all the headers it needs itself), mozilla/*.h; <*.h>, js*.h; */*.h; js*inlines.h and js*-inl.h; */*-inl.h. The public JSAPI headers in js/public/*.h should be included as js/*.h in the */*.h block. | The following order is used for includes: the module's .h (this ensures it includes all the headers it needs itself), mozilla/*.h; <*.h>, js*.h; */*.h; js*inlines.h and js*-inl.h; */*-inl.h. The public JSAPI headers in js/public/*.h should be included as js/*.h in the */*.h block. | ||