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
GNU coding standards
(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!
==Code formatting== The GNU Coding Standards specify exactly how to format most [[C (programming language)|C programming language]] constructs. Here is a characteristic example: <syntaxhighlight lang="c"> int main (int argc, char *argv[]) { struct gizmo foo; fetch_gizmo (&foo, argv[1]); check: if (foo.type == MOOMIN) puts ("It's a moomin."); else if (foo.bar < GIZMO_SNUFKIN_THRESHOLD / 2 || (strcmp (foo.class_name, "snufkin") == 0) && foo.bar < GIZMO_SNUFKIN_THRESHOLD) 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; } </syntaxhighlight> 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. Being tightly integrated with the GNU system, [[GNU Emacs]] provides automatic formatting of C code to match the GNU coding standards.<ref>{{cite web |url=https://www.gnu.org/software/emacs/manual/html_mono/ccmode.html#index-GNU-style|title=CC Mode Manual|access-date=2025-04-08}}</ref> Rather than manually modifying code formatting in a way that strays from the GNU coding standards, the formatted layout of the code can be tweaked by writing it in a more Emacs-friendly form—for example, by inserting additional parentheses. ===Splitting long lines=== "When you split an expression into multiple lines, split it before an operator, not after one."<ref>{{Cite web|url=https://www.gnu.org/prep/standards/standards.html#Formatting|title=GNU Coding Standards|website=www.gnu.org|language=en|access-date=2020-11-29}}</ref> For example: <syntaxhighlight lang="c"> if (foo_this_is_long && bar > win (x, y, z) && remaining_condition) </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)