TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C++ Coding Standard
Search

Rule:  CFL#022Checked automatically with code checker

Synopsis:Apply sizeof to an object rather than to its type
Language:C++
Severity Level:2
Category:Control Flow


Description:

Applying sizeof to an object rather than to its type has the advantage that if the object's type is changed, the sizeof expression automatically takes this into account.

This makes the code more robust.

Example:

int i;
size_t s1 = sizeof (int); // allowed if no object available
size_t s2 = sizeof i; // preferred if there is a choice