Skip to content

Commit 0252892

Browse files
committed
Proofread
1 parent fb25cb1 commit 0252892

File tree

1 file changed

+66
-21
lines changed

1 file changed

+66
-21
lines changed

CONTRIBUTING.md

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,57 @@
22

33
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
44

5-
The following is a set of guidelines for contributing to [semu](https://github.com/jserv/semu)
6-
hosted on GitHub. These are mostly guidelines, not rules. Use your best
7-
judgment, and feel free to propose changes to this document in a pull request.
5+
The following is a set of guidelines for contributing to [semu](https://github.com/sysprog21/semu)
6+
hosted on GitHub. These are mostly guidelines, not rules.
7+
Use your best judgment, and feel free to propose changes to this document in a pull request.
88

99
## Issues
1010

11-
This project uses GitHub Issues to track ongoing development, discuss project plans, and keep track of bugs. Be sure to search for existing issues before you create another one.
11+
This project uses GitHub Issues to track ongoing development, discuss project plans, and keep track of bugs.
12+
Be sure to search for existing issues before you create another one.
1213

13-
Visit our [Issues page on GitHub](https://github.com/jserv/semu/issues) to search and submit.
14+
Visit our [Issues page on GitHub](https://github.com/sysprog21/semu/issues) to search and submit.
1415

1516
## Coding Convention
1617

17-
We welcome all contributions from corporate, academic and individual developers. However, there are a number of fundamental ground rules that you must adhere to in order to participate. These rules are outlined as follows:
18-
* All code must adhere to the existing C coding style (see below). While we are somewhat flexible in basic style, you will adhere to what is currently in place. Uncommented, complicated algorithmic constructs will be rejected.
19-
* All external pull requests must contain sufficient documentation in the pull request comments in order to be accepted.
18+
Contributions from developers across corporations, academia, and individuals are welcome.
19+
However, participation requires adherence to fundamental ground rules:
20+
* Code must strictly adhere to the established C coding style (refer to the guidelines below).
21+
While there is some flexibility in basic style, it is crucial to stick to the current coding standards.
22+
Complex algorithmic constructs without proper comments will not be accepted.
23+
* External pull requests should include thorough documentation in the pull request comments for consideration.
2024

2125
Software requirement: [clang-format](https://clang.llvm.org/docs/ClangFormat.html) version 12 or later.
2226

23-
Use the command `$ clang-format -i *.[ch]` to enforce a consistent coding style.
27+
This repository consistently contains an up-to-date `.clang-format` file with rules that match the explained ones.
28+
For maintaining a uniform coding style, execute the command `clang-format -i *.[ch]`.
2429

2530
## Coding Style for Modern C
2631

27-
This coding style is a variation of the K&R style. Some general principles: honor tradition, but accept progress; be consistent;
28-
embrace the latest C standards; embrace modern compilers, their static analysis
29-
capabilities and sanitizers.
32+
This coding style is a variant of the K&R style.
33+
Adhere to established practices while being open to innovation.
34+
Maintain consistency, adopt the latest C standards,
35+
and embrace modern compilers along with their advanced static analysis capabilities and sanitizers.
3036

3137
### Indentation
3238

33-
Use 4 spaces rather than tabs.
39+
In this coding style guide, the use of 4 spaces for indentation instead of tabs is strongly enforced to ensure consistency.
40+
Consistently apply a single space before and after comparison and assignment operators to maintain readable code.
41+
Additionally, it is crucial to include a single space after every comma.
42+
e.g.,
43+
```c
44+
for (int i = 0; i < 10; i++) {
45+
printf("%d\n", i);
46+
/* some operations */
47+
}
48+
```
3449

3550
### Line length
3651

37-
All lines should generally be within 80 characters. Wrap long lines.
38-
There are some good reasons behind this:
39-
* It forces the developer to write more succinct code;
40-
* Humans are better at processing information in smaller quantity portions;
52+
All lines should typically stay within 80 characters, and longer lines should be wrapped.
53+
There are valid rationales for this practice:
54+
* It encourages concise code writing by developers.
55+
* Smaller portions of information are easier for humans to process.
4156
* It helps users of vi/vim (and potentially other editors) who use vertical splits.
4257

4358
### Comments
@@ -66,7 +81,12 @@ Leave two spaces between the statement and the inline comment.
6681
### Spacing and brackets
6782

6883
Use one space after the conditional or loop keyword, no spaces around
69-
their brackets, and one space before the opening curly bracket.
84+
their brackets, and one space before the opening curly bracket. e.g.,
85+
```c
86+
do {
87+
/* some operations */
88+
} while (condition);
89+
```
7090

7191
Functions (their declarations or calls), `sizeof` operator or similar
7292
macros shall not have a space after their name/keyword or around the
@@ -81,6 +101,8 @@ but otherwise avoid redundant or excessive brackets.
81101

82102
### Variable names and declarations
83103

104+
- Ensure that functions, variables, and comments are consistently named using English names/text.
105+
84106
- Use descriptive names for global variables and short names for locals.
85107
Find the right balance between descriptive and succinct.
86108

@@ -97,6 +119,29 @@ const uint8_t * const charmap; /* const pointer and const data */
97119
const void * restrict key; /* const pointer which does not alias */
98120
```
99121

122+
- Local variables of the same type should be declared in the same line.
123+
```c
124+
void func(void)
125+
{
126+
char a, b; /* OK */
127+
128+
char a;
129+
char b; /* Incorrect: A variable with char type already exists. */
130+
}
131+
```
132+
133+
- Always include a trailing comma in the last element of structure initialization, including its children, to assist clang-format in correctly formatting structures. However, this can be omitted in very simple and short structures.
134+
```c
135+
typedef struct {
136+
int width, height;
137+
} screen_t;
138+
139+
screen_t s = {
140+
.width = 640,
141+
.height = 480, /* comma here */
142+
}
143+
```
144+
100145
### Type definitions
101146

102147
Declarations shall be on the same line, e.g.,
@@ -418,9 +463,9 @@ printf("val %lld\n", SOME_CONSTANT);
418463

419464
#### Avoid unaligned access
420465

421-
Do not assume unaligned access is safe. It is not safe on Arm, POWER,
422-
and various other architectures. Moreover, even on x86 unaligned access
423-
is slower.
466+
Avoid assuming that unaligned access is safe.
467+
It is not secure on architectures like Arm, POWER, and others.
468+
Additionally, even on x86, unaligned access can be slower.
424469

425470
#### Avoid extreme portability
426471

0 commit comments

Comments
 (0)