Package Index Table of Contents
C/C++ ECS Test Suite Project - *.cpp
// test
/*
102. Declare a private operator new() to prohibit dynamic allocation.
*/
// bad 102
//good 102
/*
104. Declare single-parameter constructors as explicit to avoid unexpected type conversions.
*/
// good 104
// bad 104, no explicit
/*
//[ 3. Naming Conventions ]
11. Use UPPERCASE and underscores for preprocessor macro names.
*/
#define foo 143849839483 // 11. Use UPPERCASE and underscores for preprocessor macro names.
#define FOO_foo 2 // bad
#define ABX_FOO 3 // ok
// 118. Use C++ casting operators instead of C-style casts.
// BAD 118, explicit old-style cast
// good 118
#define FOO_foo 2 //
#define ABX_foo 3 // 12. Add a unique prefix to macro names.
/*
126. Use C++ streams instead of stdio functions for type safety.
*/
#include // don't use
Function Definition: main
// don't use stdio.h
// good
/*
145. Avoid break and continue in iteration statements.
*/
Function Definition: main
break; // no
continue; // no
// Avoid break and continue in iteration statements.
/*
146. Avoid multiple return statements in functions.
*/
Function Definition: main
if ( 1 ) return; // too many return path's
/*
147. Do not use goto.
*/
Function Definition: main
//Do not use goto.
//15. Pluralize the names of collections.
Shapes shape; // single, singular
Shapes shapes[10]; // multiple, plual
Shape array[10]; // BAD multipe, no plural
/*
16. Use lowerCamelCase for function names.
*/
Function Definition: Foofun
int Foofun() { // 16. Use lowerCamelCase for function names.
/*
172. Use #include sparingly in header files.
*/
// 172.h #includes "gen.h" [ prj header ], its ok for 172.h to #include <> system headers
/*
173. Implement class methods outside of their class declaration block.
*/
// bad 173, a definition should NOT be made within a class
// Very nasty practice as this is a 'deferred function' and not actually processed until end-of-class
// good 173, just a decl
Function Definition: foo
// 174. Do not name files containing tests or examples the same as template header file names.
Function Definition: main
// 175. Do not put global-scope using or using namespace declarations in a header file.
// GOOD 175, using ok in c++ file
/*
22. Name all function parameters.
*/
myclass (void); //ok
myclass(int); //bad
void method2(); // inconsistent
Function Definition: myclass
/*
23. Use "other" for parameter names in copy constructors and assignment operators.
*/
A( const A& other ); // ok
A& operator= (const A& other ); // ok
A( const A& foo ); // bad
A& operator= (const A& fum ); // bad
int h57; // 27. Avoid the use of digits within names.
// 28. Avoid excessively long names.
/*
.
30. Use lowerCamelCase for abbreviations.
*/
typedef int FOO; // 30. Use "lowerCamelCase"
/*
40. Use one-line comments to explain implementation details.
*/
// comment about the function
Function Definition: f
// comment about the next aggregate statement
Function Definition: ff
/*
42. Provide a summary description of every declared element.
*/
//GOOD foo doesn't do much
/*
43. Document the interface exposed by every function.
*/
// foo does this ..
Function Definition: foo
Function Definition: badfoo
/*
52. Label closing braces in highly nested control structure.
*/
// BAD
Function Definition: foo1
// GOOD
Function Definition: foo2
} // good
} // good
} // good
/*
64. Design for reentrancy.
*/
// multi-thread code cannot use global's each method must have unique instance
Function Definition: Thread
FOO_GLO ++; // 64. Design for reentrancy.
/*
69. Place preprocessor include guards in header files.
*/
/*
72. Add a semicolon after every statement expression macro.
*/
NOP // bad 72. Add a semicolon after every statement expression macro.
NOP; // good
/*
74. Do not use "#define" to define constants declare static const variables instead.
*/
int foomem = foo ; // big magic number -Do not use "#define" to define constants
/*
75. Use portable types for portable code.
*/
// bad over-riding #include
/*
will generate the above for you automatically this make's portable code!
It's best to #include and then let your compiler create the types for you.
*/
/*
76. Use typedefs to simplify complicated type expressions.
*/
const vector & log; // bad
Function Definition: bad
const vector & log; // bad
logtype & log; // good
Function Definition: good
logtype & log; // good
/*
77. Create a zero-valued enumerator to indicate an uninitialized, invalid, unspecified, or default state.
*/
// zero value, added zero intialization as comment
// bad NO Default, or None, ...
// false positive exclusion
/*
78. Do not define enumerations using macros or integer constants.
*/
// BAD don't use macro constants, use enum
// BAD also ..
/*
79. Declare enumerations within a namespace or class.
*/
// bad, global space
// good nmsp
// good class space
/*
80. Declare global functions, variables, or constants as static members of a class.
*/
// bad, should be static in class
// good
/*
81. Declare for-loop iteration variables inside of for statements.
*/
// a loop iterator variable must be local to for-loop
Function Definition: main
for ( i=0; i<1; i++ ) { // BAD 81
for ( int i=0; i<10; i++ ) { // GOOD 81
/*
82. Use an enumeration instead of a Boolean to improve readability.
*/
void noop(bool); //BAD 82 DECL
Function Definition: fooop
//BAD 82 Usage
foo.noop(true); // this has questionable meaning
//GOOD 82
foo.noop(foo::aloud); // this is clear?
/*
84. Accept objects by reference and primitive or pointer types by value.
*/
//GOOD 84
//BAD 84, primitive types must be passed by value
// 87. Do not use void* in a public interface.
void * foo(); // BAD 87
void * foam(); // GOOD 87
/*
88. Use inline functions instead of macros.
*/
Function Definition: SQRT
Function Definition: main
hypo = _SQRT ( 2 ); // BAD 88, don't use macros
hypo = SQRT ( 2 ); // GOOD 88, inline
/*
9. Include white space.
*/
Function Definition: main
while(1) { } ; // need space after while
do{ } while(1); // need space after do and while
// 96. Avoid the use of friend declarations.
// bad 96, don't use friend
/*
97. Declare an explicit default constructor for added clarity.
*/
// bad 97, no con
// good 97, has con
/*
170. Use the class name as the filename.
*/
// GOOD 170 class name like file name
// BAD 170 file name not like class name
#include // bad
#define foo 143849839483 // 11. Use UPPERCASE and underscores for preprocessor macro names.
#define FOO_foo 2 //
#define ABX_foo 3 // 12. Add a unique prefix to macro names.
NOP // bad 72. Add a semicolon after every statement expression macro.
NOP; // good
class foo1; // fwd decl
Function Definition: Foo
Foo() {} // DUMMY Fun def
int h57; // 27. Avoid the use of digits within names.
typedef int FOO; // 30. Use "lowerCamelCase"
int foomem = foo ; // big magic number -Do not use "#define" to define constants
Function Definition: Foofun
int Foofun() { // 16. Use lowerCamelCase for function names.
FOO_GLO ++; // 64. Design for reentrancy.
// 174. Do not name files containing tests or examples the same as template header file names.
Function Definition: main
Package Index Table of Contents
CodeCheck Copyright (c) 1988-2005 by Abraxas Software Inc. (R). All rights reserved.