aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc/dev_style.txt
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:39:54 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:39:54 +0000
commit21cb7d04c387e4198ca8098a884c78b56ffcf4c2 (patch)
tree84fe5690df1551f0bb2bdfe1a13aacd29ebc1de7 /runtime/doc/dev_style.txt
parentd9c904f85a23a496df4eb6be42aa43f007b22d50 (diff)
parent4a8bf24ac690004aedf5540fa440e788459e5e34 (diff)
downloadrneovim-colorcolchar.tar.gz
rneovim-colorcolchar.tar.bz2
rneovim-colorcolchar.zip
Merge remote-tracking branch 'upstream/master' into colorcolcharcolorcolchar
Diffstat (limited to 'runtime/doc/dev_style.txt')
-rw-r--r--runtime/doc/dev_style.txt66
1 files changed, 52 insertions, 14 deletions
diff --git a/runtime/doc/dev_style.txt b/runtime/doc/dev_style.txt
index b96b01dbff..cb28f1a845 100644
--- a/runtime/doc/dev_style.txt
+++ b/runtime/doc/dev_style.txt
@@ -32,19 +32,13 @@ but we nonetheless keep things as they are in order to preserve consistency.
Header Files *dev-style-header*
-The #define Guard ~
+Header guard ~
-All header files should have `#define` guards to prevent multiple inclusion.
-The format of the symbol name should be `NVIM_<DIRECTORY>_<FILE>_H`.
+All header files should start with `#pragma once` to prevent multiple inclusion.
In foo/bar.h:
>c
- #ifndef NVIM_FOO_BAR_H
- #define NVIM_FOO_BAR_H
-
- ...
-
- #endif // NVIM_FOO_BAR_H
+ #pragma once
<
@@ -245,15 +239,13 @@ contain only non-static function declarations. >c
// src/nvim/foo.h file
- #ifndef NVIM_FOO_H
- #define NVIM_FOO_H
+ #pragma once
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "foo.h.generated.h"
#endif
- #endif // NVIM_FOO_H
64-bit Portability ~
@@ -846,7 +838,7 @@ Annotate non-trivial fall-through between cases.
If not conditional on an enumerated value, switch statements should always
have a `default` case (in the case of an enumerated value, the compiler will
warn you if any values are not handled). If the default case should never
-execute, simply `assert`: >c
+execute, simply use `abort()`: >c
switch (var) {
case 0:
@@ -856,8 +848,54 @@ execute, simply `assert`: >c
...
break;
default:
- assert(false);
+ abort();
+ }
+
+Switch statements that are conditional on an enumerated value should not have
+a `default` case if it is exhaustive. Explicit case labels are preferred over
+`default`, even if it leads to multiple case labels for the same code. For
+example, instead of: >c
+
+ case A:
+ ...
+ case B:
+ ...
+ case C:
+ ...
+ default:
+ ...
+
+You should use: >c
+
+ case A:
+ ...
+ case B:
+ ...
+ case C:
+ ...
+ case D:
+ case E:
+ case F:
+ ...
+
+Certain compilers do not recognize an exhaustive enum switch statement as
+exhaustive, which causes compiler warnings when there is a return statement in
+every case of a switch statement, but no catch-all return statement. To fix
+these spurious errors, you are advised to use `UNREACHABLE` after the switch
+statement to explicitly tell the compiler that the switch statement always
+returns and any code after it is unreachable. For example: >c
+
+ enum { A, B, C } var;
+ ...
+ switch (var) {
+ case A:
+ return 1;
+ case B:
+ return 2;
+ case C:
+ return 3;
}
+ UNREACHABLE;
Return Values ~