Next: High Integrity CPP Guideline 8.4.12  Up: 8.4 Object Declarations and Definitions  Previous: High Integrity CPP Guideline 8.4.10  Contents

High Integrity CPP Rule 8.4.11   Use 'const' whenever possible.

Justification

This allows specification of semantic constraint which a compiler can enforce. It communicates to other programmers that value should remain invariant - by explicit statement. For example, specify whether a pointer itself is const, the data it points to is const, both or neither:

   
   char* p1;              // non-const pointer, non-const data
   const char* p2;        // non-const pointer, const data
   char* const p3;        // const pointer, non-const data
   const char* const p4;  // const pointer, const data
Reference

Effective C++ Item 21;


HICPP VERSION 2.4  http://www.codingstandard.com   Copyright: © 2007 THE PROGRAMMING RESEARCH GROUP