Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - Formatting code

Node:Formatting code, Next:, Previous:Style, Up:Style



Formatting code

Place the open curly bracket that starts the body of a C function in the first column of your source file, and avoid placing any other open brackets or open parentheses in that column. This will help many code-processing utilities find the beginnings of your functions. Similarly, you should also place the name of your functions within your function definitions in the first column. Thus, your functions should resemble the following example:

static char *
concat (char *s1, char *s2)
{
  ...
}

When you split an expression into multiple lines, split it before an operator, not after one. Here is the right way:

if (foo_this_is_long && bar > win (x, y, z)
    && remaining_condition)

Don't declare multiple variables in one declaration that spans lines. Start a new declaration on each line instead. For example, instead of this:

int    foo,
       bar;

write either this:

int foo, bar;

or this:

int foo;
int bar;

 
 
  Published under free license. Design by Interspire