-
Notifications
You must be signed in to change notification settings - Fork 455
Coding Style
Jianxin Xiong edited this page Sep 17, 2025
·
2 revisions
This is mentioned in the Wiki Home Page, but a separate page is easier to find.
The coding style of this project resembles that of the linux kernel, please match your contributions to the prevailing style in the files.
Switch statement:
switch (suffix) {
case 'G':
case 'g':
mem <<= 30;
break;
case 'M':
case 'm':
mem <<= 20;
break;
case 'K':
case 'k':
mem <<= 10;
fallthrough;
default:
break;
}
Braces:
No braces for single line.
if (condition)
do_this();
else
do_that();
Use braces consistently for if and else branches.
if (condition) {
do_this();
do_that();
} else {
otherwise();
}
Use braces to increase readability.
while (condition) {
if (test)
do_something();
}
For function definition { should start on a new line.
int function(int x)
{
body of function
}
Multiline Function Call/Prototype Alignment:
option 1: align the argumnents with the first one. Use tab as many as possible and only use space to fill the last gap.
ssize_t (*copy_from_hmem_iov)(void *dest, size_t size,
enum fi_hmem_iface iface, uint64_t device,
const struct iovec *hmem_iov,
size_t hmem_iov_count,
uint64_t hmem_iov_offset);
option 2: use tab to align the rest lines.
ssize_t (*copy_from_hmem_iov)(void *dest, size_t size,
enum fi_hmem_iface iface, uint64_t device,
const struct iovec *hmem_iov,
size_t hmem_iov_count,
uint64_t hmem_iov_offset);