GNU coding standards: Difference between revisions

Content deleted Content added
Kl4m-AWB (talk | contribs)
Replace/move Free Software portal box + various. using AWB
m Code formatting: Source markup
Line 5:
The GNU coding standards specify exactly how to format most [[C (programming language)|C programming language]] constructs. Here is a characteristic example:
 
<source lang="c">
''int''
int
main (''int'' argc, ''char'' *argv[])
{
''struct gizmo'' foo;
 
fetch_gizmo (&foo, argv[1]);
 
<span style="text-decoration: underline">check</span>:
check:
'''if''' (foo.type == MOOMIN)
putsif ("It'sfoo.type a== moomin."MOOMIN);
puts ("It'''s a moomin.");
else if''' (foo.bar < GIZMO_SNUFKIN_THRESHOLD
|| (strcmp (foo.class_name, "snufkin") == 0)
&& foo.bar < GIZMO_SNUFKIN_THRESHOLD / 2)
puts ("It's a snufkin.");
'''else'''
{
''char'' *barney; ''/* Pointer to the first character after''
''the last slash in the file name. */''
''int'' wilma; ''/* Approximate size of the universe. */''
''int'' fred; ''/* Max value of the `bar' field. */''
 
'''do'''
{
frobnicate (&foo, GIZMO_SNUFKIN_THRESHOLD,
&barney, &wilma, &fred);
twiddle (&foo, barney, wilma + fred);
}
'''while''' (foo.bar >= GIZMO_SNUFKIN_THRESHOLD);
 
store_size (wilma);
 
'''goto''' check;
}
 
'''return''' 0;
}
</source>
 
The consistent treatment of blocks as statements (for the purpose of indentation) is a very distinctive feature of the GNU C code formatting style; as is the mandatory space before parentheses. All code formatted in the GNU style has the property that each closing brace, bracket or parenthesis appears ''to the right'' of its corresponding opening delimiter, or in the same column.