Here are guidelines for the typical, preferred coding style.  The guidelines
can grow with time.  Typically, it is safe simply to mimic the existing code.

Lines should be at most 80 characters wide.  Indentation styles for continuing
lines vary, but continued lines should be shorter and start further to the
right than their parents.  Ideally, user-visible strings will only be split
such that one can still grep for them in the source code.

Statements should be indented with tab characters.  Align case labels with
their switch statements.

There should generally be neither whitespace at the ends of lines nor blank
lines at the ends of files.  (A common exception to the blank-line rule is
.r results files in the test suite.)

An opening brace should be last on its line and a closing brace first.  E.g.,
	if (foo) {
		bar1();
		bar2();
	}

While this guideline applies to non-function statement blocks (if, switch, for,
while, do), functions should have their opening brace alone on its own line.
Function definitions should also have their name at the beginning of the line.
E.g.,
	uint_t
	dt_cg_tramp_prologue(dt_pcb_t *pcb)
	{
		return dt_cg_tramp_prologue_act(pcb, DT_ACTIVITY_ACTIVE);
	}

In an "if...else if...else" statement, omit braces for the final branch if
its block comprises only a single, simple statement.  Omit braces for all
previous branches if and only if all those previous branches each comprise
only a single, simple statement.  That is, after the initial "if" branch,
all subsequent branches must start with either "else" or else "} else".
For example,
	if (foo1) {
		bar1();
	} else if (foo2) {
		bar2();
		bar3();
	} else
		bar4();
The "else if (foo2)" branch needs braces since its block has two statements.
Therefore, other branches also need braces, though the final branch is immune
to this requirement.

Regarding the above, a nested if-statement is equivalent to multiple statements.
E.g.,
	if (foo1) {                       /* good */
		if (foo2)
			bar1;
	}
	if (foo1)                         /*  bad */
		if (foo2)
			bar1;

A space should appear:

  - after these keywords: if, switch, case, for, do, while

  - on each side of most binary and ternary operators, such as:
	=  +  -  <  >  *  /  %  |  &  ^  <=  >=  ==  !=  ?  :

A space should NOT appear:

  - immediately inside parentheses in C code or D scripts;  e.g.,
       (foo > 0)       /* good */
      ( foo > 0 )      /*  bad */

  - after unary operators, such as  &  *  +  -  ~  !

  - after sizeof typeof alignof __attribute__ defined

  - after typecast operators -- e.g.,
       (int)x          /* good */
       (int) x         /*  bad */

  - after  the unary  prefix operators ++ and --

  - before the unary postfix operators ++ and --

  - around the . and -> structure member operators

When declaring pointers, the * should be adjacent to the pointer name, not
to the type name.  E.g.,
	char *dd_name;
	void *dt_buf_ptr(const dt_buf_t *bp);

This * rule is for declaration.  For a function definition, the function
name remains at the beginning of the line, as previously mentioned.  E.g.,
	void *
	dt_buf_ptr(const dt_buf_t *bp)
	{
		return bp->dbu_buf;
	}

Macros with multiple statements should be enclosed in a do-while(0) block:
	#define DT_CG_AGG_SET_STORAGE(aid, sz) \
		do { \
			if ((aid)->di_offset == -1) \
				dt_ident_set_storage((aid), 2 * (sz)); \
		} while (0)
Note there is no final semicolon.

Function calls should not unnecessarily be cast to void.  E.g.,
	printf("hello world\n");                    /* good */
	(void) printf("hello world\n");             /*  bad */

The return argument typically needs no parentheses.  E.g.,
	return 0;                                   /* good */
	return (0);                                 /*  bad */
