agentleFS
FuwnFuwn/suckless-agent-skills/skills/coding-style/SKILL.md

coding-style

Skill18 starsChanged 7 months agoMITView on GitHub

Coding style guidelines for C and POSIX code, covering layout, formatting, declarations, headers, and consistency expectations.

11 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

30 rules. 0 are common, 17 are distinctive, and 13 are very specific to this project.

  • 0

    Common

    Most of the 11 edited versions we read keep these.

  • 17

    Distinctive

    This author's own choices. Worth a look.

  • 13

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use C99 without extensions (ISO/IEC 9899:1999).

    line 41
  2. Very specific:

    When using gcc define _POSIX_C_SOURCE 200809L.

    line 43
  3. Distinctive:

    Do not mix declarations and code.

    line 45
  4. Distinctive:

    Do not use for loop initial declarations.

    line 46
  5. Very specific:

    Use /* */ for comments, not //.

    line 47
  6. Distinctive:

    All variable declarations at top of block.

    line 55
  7. Distinctive:

    Use block for single statement if inner statement needs a block.

    line 59
  8. Distinctive:

    Use block if another branch of the same statement needs a block:

    line 68
  9. Distinctive:

    Use tabs for indentation and spaces for alignment.

    line 80
  10. Distinctive:

    No tabs except beginning of line.

    line 83
  11. Very specific:

    Use spaces - not tabs - for multiline macros as the indentation level is 0, where the #define began.

    line 84
  12. Very specific:

    Use a space after if, for, while, switch (they are not function calls).

    line 115
  13. Very specific:

    Do not use a space after the opening ( and before the closing ).

    line 116
  14. Very specific:

    Do not use a space with sizeof().

    line 118
  15. Distinctive:

    Do not indent cases another level.

    line 123
  16. Distinctive:

    Place system/libc headers first in alphabetical order.

    line 140
  17. Distinctive:

    If headers must be included in a specific order add a comment to explain.

    line 141
  18. Distinctive:

    Place local headers after an empty line.

    line 142
  19. Distinctive:

    When writing and using local headers.

    line 143
  20. Distinctive:

    Instead ensure they are included where and when they are needed.

    line 145
  21. Very specific:

    Read <https://talks.golang.org/2012/splash.article#TOC_5.>

    line 146
  22. Very specific:

    Read <http://plan9.io/sys/doc/comp.html>

    line 147
  23. Very specific:

    Do not use type_t naming (it is reserved for POSIX and less readable).

    line 152
  24. Distinctive:

    Do not typedef builtin types.

    line 154
  25. Very specific:

    Use CamelCase for typedef'd types.

    line 155
  26. Distinctive:

    Keep lines to reasonable length (max 79 characters).

    line 160
  27. Very specific:

    Do not use C99 bool types (stick to integer types).

    line 165
  28. Very specific:

    When functions return -1 for error test against 0 not -1:

    line 174
  29. Very specific:

    Use goto to unwind and cleanup when necessary instead of multiple nested levels.

    line 179
  30. Distinctive:

    Use enums for values that are grouped semantically and #define otherwise:

    line 190

“Common” is measured: kept by at least 6 in 10 of the 11 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Style

Note that the following are guidelines and the most important aspect of style is consistency. Strive to keep your style consistent with the project on which you are working. It is up to the project maintainer to take some liberty in the style guidelines.

Recommended Reading

The following contain good information, some of which is repeated below, some of which is contradicted below.

File Layout

  • Comment with LICENSE and possibly short explanation of file/tool.
  • Headers
  • Macros
  • Types
  • Function declarations:
    • Include variable names.
    • For short files these can be left out.
    • Group/order in logical manner.
  • Global variables.
  • Function definitions in same order as declarations.
  • main

C Features

  • Use C99 without extensions (ISO/IEC 9899:1999).
  • Use POSIX.1-2008:
    • When using gcc define _POSIX_C_SOURCE 200809L.
    • Alternatively define _XOPEN_SOURCE 700.
  • Do not mix declarations and code.
  • Do not use for loop initial declarations.
  • Use /* */ for comments, not //.
  • Variadic macros are acceptable, but remember:
    • __VA_ARGS__ not a named parameter.
    • Arg list cannot be empty.

Blocks

  • All variable declarations at top of block.
  • { on same line preceded by single space (except functions).
  • } on own line unless continuing statement (if else, do while, ...).

Use block for single statement if inner statement needs a block.

for (;;) {
	if (foo) {
		bar;
		baz;
	}
}

Use block if another branch of the same statement needs a block:

if (foo) {
	bar;
} else {
	baz;
	qux;
}

Leading Whitespace

Use tabs for indentation and spaces for alignment. This ensures everything will line up independent of tab size. This means:

  • No tabs except beginning of line.
  • Use spaces - not tabs - for multiline macros as the indentation level is 0, where the #define began.

Functions

  • Return type and modifiers on own line.
  • Function name and argument list on next line. This allows to grep for function names simply using grep ^functionname(.
  • Opening { on own line (function definitions are a special case of blocks as they cannot be nested).
  • Functions not used outside translation unit should be declared and defined static.

Example:

static void
usage(void)
{
	eprintf("usage: %s [file ...]\n", argv0);
}

Variables

  • Global variables not used outside translation unit should be declared static.
  • In declaration of pointers the * is adjacent to variable name, not type.

Keywords

  • Use a space after if, for, while, switch (they are not function calls).
  • Do not use a space after the opening ( and before the closing ).
  • Preferably use () with sizeof.
  • Do not use a space with sizeof().

Switch

  • Do not indent cases another level.
  • Comment cases that FALLTHROUGH.

Example:

switch (value) {
case 0: /* FALLTHROUGH */
case 1:
case 2:
	break;
default:
	break;
}

Headers

User Defined Types

  • Do not use type_t naming (it is reserved for POSIX and less readable).
  • Typedef opaque structs.
  • Do not typedef builtin types.
  • Use CamelCase for typedef'd types.

Line Length

  • Keep lines to reasonable length (max 79 characters).

Tests and Boolean Values

  • Do not use C99 bool types (stick to integer types).
  • Otherwise use compound assignment and tests unless the line grows too long:

    if (!(p = malloc(sizeof(*p)))) hcf();

Handling Errors

  • When functions return -1 for error test against 0 not -1:

    if (func() < 0) hcf();

  • Use goto to unwind and cleanup when necessary instead of multiple nested levels.
  • return or exit early on failures instead of multiple nested levels.
  • Unreachable code should have a NOTREACHED comment.
  • Think long and hard on whether or not you should cleanup on fatal errors. For simple "one-shot" programs (not daemons) it can be OK to not free memory. It is advised to cleanup temporary files however.

Enums and #define

Use enums for values that are grouped semantically and #define otherwise:

#define MAXSZ  4096
#define MAGIC1 0xdeadbeef

enum {
	DIRECTION_X,
	DIRECTION_Y,
	DIRECTION_Z
};

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.