Null Statements

In C++, it's possible to have a null statement, a statement consisting entirely of a semicolon, as shown here:

Example 19-23. C++ Example of a Traditional Null Statement

while ( recordArray.Read( index++ ) != recordArray.EmptyRecord() )
   ;

The while in C++ requires that a statement follow, but it can be a null statement. The semicolon on a line by itself is a null statement. Here are guidelines for handling null statements in C++:

Call attention to null statements. Null statements are uncommon, so make them obvious. One way is to give the semicolon of a null statement a line of its own. Indent it, just as you would any other statement. This is the approach shown in the previous example. Alternatively, you can use a set of empty braces ...

Get Code Complete, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.