coding guide

David Mosberger-Tang (David.Mosberger@acm.org)
Sat, 4 Apr 1998 16:50:19 -0800

Hi everyone,

I finally got tired of telling the same story over and over again, so
I put together a short list of rules that should help keeping SANE
portable and easy to maintain. I appended a copy below. Comments are
welcome and additions too, though I don't want to have this degenerate
into a long document that nobody wants to read...

Cheers,

--david

--------------------------------------
Sat Apr 4 16:22:00 1998

Here are a few rules that should help writing a SANE-conformant
backend:

* Please follow the GNU coding standards. It's clear that the style
outlined there is nobody's favorite, but it's much easier to
maintain SANE if everybody follows more or less the same coding
style. It also looks more professional. The GNU standards can be
found at:

http://www.gnu.org/prep/standards_toc.html
ftp://ftp.gnu.org/pub/gnu/standards/standards.text

Note that GNU emacs supports automatic indentation according to this
standard. The command "indent -gnu" can be used to reformat
existing sources according to this standard.

* Please be curteous to programmer's with terminals that are 80
characters wide. It's not difficult to avoid long lines, so please
do so. Note that in ANSI C you can split long strings into pieces
separated by white space. For example,
"this is an awfully long string" can be written as "this is an "
"awfully long string".

* Please do not assume that `size_t' is `unsigned int'. On some
systems, it's `unsigned long' and the size of this type may be
bigger than that of an int (this is true for practially any of the
64-bit systems). To print a variable of type size_t portably, cast
the variable to u_long and print it with the %lu specifier. E.g.:

size_t len;

printf ("len=%lu\n", (u_long) len);

* Please do not depend on GNU C specific features or, if you do, make
the dependency conditional so other compilers will still be able to
compile the files. In particular:

- do not use C++ style comments (//-line comments)

- do not declare dynamically sized automatic arrays; instead,
use alloca() after including <lalloca.h>. For example:

void
func (int n)
{
char buf[n];
}

should be re-written as:

#ifdef _AIX
# include <lalloca.h> /* MUST come first for AIX! */
#endif

#include "sane/config.h"
#include <lalloca.h>
:
void
func (int n)
{
char *buf = alloca (n);
}

--
Source code, list archive, and docs: http://www.mostang.com/sane/
To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com