Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Indentation style
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== BSD KNF === The [[Berkeley Software Distribution]] (BSD) operating systems uses a style that is sometimes termed [[kernel normal form]] (KNF). Although mostly intended for kernel code, it is also widely used in [[userland (computing)|userland]] code. It is essentially a thoroughly documented variant of K&R style as used in the Bell Labs version 6 & 7 [[Unix]] source code.<ref name="C Style and Coding Standards for SunOS">{{cite news |last1=Shannon |first1=Bill |title=C Style and Coding Standards for SunOS |url=https://www.cis.upenn.edu/~lee/06cse480/data/cstyle.ms.pdf |access-date=15 June 2019 |version=1.8 |publisher=Sun Microsystems, Inc. |date=19 August 1996}}</ref> The SunOS kernel and userland uses a similar indentation style.<ref name="C Style and Coding Standards for SunOS" /> Like KNF, this also was based on AT&T style documents and is sometimes termed Bill Joy Normal Form.<ref name="DTraceToolkit Style Guide">{{cite web |last1=Gregg |first1=Brendan |title=DTraceToolkit Style Guide |url=http://www.brendangregg.com/DTraceToolkit/style.html |access-date=6 February 2015}}</ref> The SunOS guideline was published in 1996; ANSI C is discussed briefly. The correctness of the indentation of a list of source files can be verified by the ''cstyle'' program written by Bill Shannon.<ref name="C Style and Coding Standards for SunOS" /><ref name="DTraceToolkit Style Guide" /><ref name="illumos-gate cstyle">{{cite web |url=https://github.com/illumos/illumos-gate/blob/master/usr/src/tools/scripts/cstyle.pl |title=cstyle.pl |last1=Shannon |first1=Bill |date=9 September 1998 |website=illumos-gate |publisher=Sun Microsystems, Inc. |access-date=6 February 2015 |version=1.58}}</ref> In this style, the hard tabulator (ts in [[Vi (text editor)|vi]]) is kept at eight columns, while a soft tabulator is often defined as a helper also (sw in vi), and set at four. The hard tabulators are used to indent code blocks, while a soft tabulator (four spaces) of additional indentation is used for all continuing lines that must be split over multiple lines. Moreover, function calls do not use a space before the parenthesis, although C-language native statements such as <code>if</code>, <code>while</code>, <code>do</code>, <code>switch</code> and <code>return</code> do (in the case where <code>return</code> is used with parens). Functions that declare no local variables in their top-level block should also leave an empty line after their opening block brace. Examples: <syntaxhighlight lang=c> while (x == y) { something(); something_else(); } final_thing(); </syntaxhighlight> <syntaxhighlight lang=c> if (data != NULL && res > 0) { if (JS_DefineProperty(cx, o, "data", STRING_TO_JSVAL(JS_NewStringCopyN(cx, data, res)), NULL, NULL, JSPROP_ENUMERATE) != 0) { QUEUE_EXCEPTION("Internal error!"); goto err; } PQfreemem(data); } else { if (JS_DefineProperty(cx, o, "data", OBJECT_TO_JSVAL(NULL), NULL, NULL, JSPROP_ENUMERATE) != 0) { QUEUE_EXCEPTION("Internal error!"); goto err; } } </syntaxhighlight> <syntaxhighlight lang=c> static JSBool pgresult_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { QUEUE_EXCEPTION("PGresult class not user-instantiable"); return (JS_FALSE); } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)