The full style guide is further below in secotion Style Guide.
Here is an example C project that’ll give you an idea of what code should look like, to make it easily readable for everyone.
The project structure is like this:
linkedlist/
├─ .editorconfig
├─ .gitignore
├─ include/
│ └─ linkedlist.h
├─ src/
│ └─ linkedlist.c
└─ tests/
└─ test_cases.c
It’s a good idea to separate API header files in their own folder (include). Internal header files can safely go into src though.
And here’s the important part of the content of the files each.
For now, just have a look at linkedlist.h for a public API header file.
The sample is linkedlist.c.
Whether or not to use K&R or Allman is
subject to discussion right now.
In general you want to make sure that you do not cross the 79
character line width, use 4 spaces to indent (set up your editor to do
that when you press Tab), and use \n as line
breaks.
Some editors require plugins to support the .editorconfig file as is.
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
[Makefile]
indent_style = tab
tab_width = 4
[*.{c,h}]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
max_line_length = 79
curly_bracket_next_line = false
spaces_around_brackets = both
spaces_around_operators = hybrid
indent_brace_style = K&R
# indent_brace_style = Allman
The sample .gitignore includes settings to ignore the generated output files from C (*.{o,la,so} etc), patch related files (*.{rej,orig}), and various IDE file things.
The settings are a blunt rip-off from github’s gitignore repository.
Coming soon™, going to be a shameless rip-off of https://www2.cs.arizona.edu/~mccann/cstyle.html
The following build systems are somewhat standard:
To write unit tests you could use frameworks like gtest (for C++) or simpler frameworks like test.h.
What framework to use is a matter of taste. Just be sure to have some unit tests (and integrated into your build system).