Defining Programming Standards   
for Professional Programmers 
  

         

Home

Contents

1: Standards

2: Psychological Factors

3: General Principles

4: Commenting

5: Naming

6: Code Layout

7: File Layout

8: Language Usage

9: Data Usage

10: Programming Usage

11: Implementing Standards

A: Example Standard

B: References

C: Glossary

Syque

About

Share this page:

Google
C Style
syque.com
Web

 

 

Books and
more at:

USA:

In association with amazon.com

UK:

In Association with Amazon.co.uk

Canada:

In Association with amazon.ca

 

 

CHAPTER 6 : Layout

PART 3 : LAYOUT

CHAPTER 6 : Code Layout
6.1 Basic principles of code layout
6.2 Use of Spaces
6.3 Use of blank lines
6.4 Use vertical alignment
6.5 Indentation level
6.6 Line wrapping
6.7 Braces
6.8 Use of parentheses
6.9 Nested single statement
6.10 Empty statements
6.11 'else..if'
6.12 'switch' statements
6.13 'do..while'
6.14 Labels
6.15 Data declarations
6.16 Function declaration
6.17 Preprocessor commands
6.18 Summary

<--Prev page | Next page -->

 

6.10  Empty statements

Empty statements naturally occur after control statements where the entire operation is contained within the control statement. This is, in effect, a special case of the single statement as described above, and similar rules may be used.

Putting the semicolon at the end of the line can be confusing, even though the next line is not indented. The careful reader will be alerted by this, and will want to check that this is what was intended:

 

for ( i = 0; i < ARRAY_MAX; NewArray[i++] = 0 );
SetupArray( NewArray );

-------------------------------------------------

A clearer alternative is to put the semicolon by itself on the next line, either below the for or indented, where the intent is explicit, saying "Do nothing". For  additional confirmation, a comment may be added:

 

for ( i = 0; i < ARRAY_MAX; NewArray[i++] = 0 )
    ; /* do nothing */

 

Another alternative is to use an empty set of braces. This is sticking to the simple 'braces with everything' rule, is not likely to be missed, and eases later line insertion. This is at the cost of additional brace-only lines (although, in practice, these are not likely to happen too often).

 

for ( i = 0; i < ARRAY_MAX; NewArray[i++] = 0 )
{
}

 

<--Prev page | Next page -->

 

  © Syque 1995-2010

Massive Content -- Maximum Speed