Sample Listing File for XYZ C++ Analysis
Abraxas Software (R) CodeCheck Mac version 6.01
Checking Borland C++ file xyz_test.c with rules from xyzrule.cc:
1 /* xyz_test.c
------- A
A: Warning W9411: Use // comments, not /*...*/ comments.
2 ==============================================================================
3 Purpose: Test file for the XYZ CodeCheck rule file.
4 Written: 1 December 1995.
5 Revised: 2 January 1996.
6 Format: Monospaced font with 4 spaces/tab.
7 ==============================================================================
9 */
10
11
12 #if defined(macintosh) || defined(unix)
13 // The following two include directives can be tested
14 // only under operating systems that allow long filenames.
15 #include "nametoolong.h" // header with filename too long
------- A
A: Warning W9111: Header filename nametoolong.h is not in DOS 8.3 format.
================================================================
Checking nametoolong.h
1 1 // This is a test header file
1 2 // With a filename that is too long for DOS
1 3
1 4 int zork;
------- A
A: Warning W9213: Header file nametoolong.h should be wrapped in an #ifndef.
================================================================
Resume checking xyz_test.c
16 #include "header.bleep" // header with extension too long
------- A
A: Warning W9111: Header filename header.bleep is not in DOS 8.3 format.
================================================================
Checking header.bleep
1 1 // This is a test header file
1 2 // With an extension that is too long for DOS.
================================================================
Resume checking xyz_test.c
17 #endif
18
19 #include "no_wrap1.h" // header begins with define
================================================================
Checking no_wrap1.h
1 1
1 2 #define BLEEP 12345
------- A B
A: Warning W9213: Header file no_wrap1.h should be wrapped in an #ifndef.
B: Warning W9212: File no_wrap1.h needs a leading comment block.
1 3
1 4 // This header file has no wrapper.
1 5 // (It begins with a #define directive).
1 6 // It also has no leading comment block.
1 7
1 8
================================================================
Resume checking xyz_test.c
20 #include "no_wrap2.h" // header begins with code
================================================================
Checking no_wrap2.h
1 1
1 2 // This header file has no wrapper.
1 3 // It begins with C++ code.
1 4 // It does have a leading comment block.
1 5
1 6 float zoom;
1 7 const int abc = 123;
------- A
A: Warning W9431: Global constant abc should be a class member.
1 8
1 9
1 10 float fun( int x )
1 11 {
1 12 return x + zoom;
1 13 }
================================================================
Resume checking xyz_test.c
21 #include "no_wrap3.h" // header begins with include
================================================================
Checking no_wrap3.h
1 1
1 2 // This header file has no wrapper.
1 3 // It begins with an #include of a file in an excluded directory.
1 4
1 5 #include <stdio.h
------- A
A: Warning W9213: Header file no_wrap3.h should be wrapped in an #ifndef.
================================================================
Reading stdio.h
2 1 /************************************************************
2 2
2 3 StdIO.h
2 4 Input / output
2 5
2 6 Copyright © Apple Computer,Inc. 1985-1991, 1993-1994.
2 7
2 8 Copyright American Telephone & Telegraph
2 9 Used with permission, Apple Computer Inc. (1985)
2 10 All Rights Reserved.
2 11
2 12 ************************************************************/
2 13
2 14
2 15 #ifndef __STDIO__
2 16 #define __STDIO__
2 17
2 18 #ifndef NULL
2 19 #define NULL 0
2 20 #endif
2 21
(a lot of material from stdio.h was removed for clarity and brevity)
2 281
2 282 #endif
================================================================
Resume checking no_wrap3.h
1 6
1 7
1 8
================================================================
Resume checking xyz_test.c
22 #include "bad_wrap.h" // header with misspelled wrapper
================================================================
Checking bad_wrap.h
1 1 // This header file has a misspelled wrapper macro name
1 2
1 3 #ifndef BADWRAP
1 4 #define BADWRAP
------- A
A: Warning W9213: BADWRAP is not the correct wrapper name for this file.
1 5
1 6 int bleep;
1 7
1 8 #endif // BADWRAP
================================================================
Resume checking xyz_test.c
23 #include "xyz_test.h"
================================================================
Checking xyz_test.h
1 1 // This is a test C++ header file
1 2
1 3 #define constructor
------- A
A: Warning W9213: Header file xyz_test.h should be wrapped in an #ifndef.
1 4 #define destructor
1 5
1 6 #define MANIFEST 1234
------- A
A: Warning W9421: Declare MANIFEST as a const, not a macro.
1 7
1 8 class Bleep
1 9 {
------- A
A: Warning W9121: Class names must begin with "XYZ_"
1 10 int default_access1_;
------- AB
A: Warning W9221: Public section must come first in class Bleep.
B: Warning W9281: Declare default_access1_ using a typedef name, not a basic C type.
1 11 int Default_access2;
------- ABC
A: Warning W9131: Private data member name Default_access2 must not begin in uppercase.
B: Warning W9131: Private data member name Default_access2 must end with an underscore.
C: Warning W9281: Declare Default_access2 using a typedef name, not a basic C type.
1 12
1 13 protected:
1 14 int protected_mem1;
------- AB
A: Warning W9222: Data member protected_mem1 of class Bleep must be private.
B: Warning W9281: Declare protected_mem1 using a typedef name, not a basic C type.
1 15
1 16 public:
1 17 int public_mem1;
------- AB
A: Warning W9222: Data member public_mem1 of class Bleep must be private.
B: Warning W9281: Declare public_mem1 using a typedef name, not a basic C type.
1 18
1 19 private:
1 20 int private_mem1;
------- AB
A: Warning W9131: Private data member name private_mem1 must end with an underscore.
B: Warning W9281: Declare private_mem1 using a typedef name, not a basic C type.
1 21 int Private_mem2;
------- ABC
A: Warning W9131: Private data member name Private_mem2 must not begin in uppercase.
B: Warning W9131: Private data member name Private_mem2 must end with an underscore.
C: Warning W9281: Declare Private_mem2 using a typedef name, not a basic C type.
1 22 int private_mem3_;
------- A
A: Warning W9281: Declare private_mem3_ using a typedef name, not a basic C type.
1 23 int Private_mem4_;
------- AB
A: Warning W9131: Private data member name Private_mem4_ must not begin in uppercase.
B: Warning W9281: Declare Private_mem4_ using a typedef name, not a basic C type.
1 24
1 25 void private_fcn1(int);
------- A
A: Warning W9131: Private function name private_fcn1 must end with an underscore.
1 26 void Private_fcn2(int);
------- AB
A: Warning W9131: Private function name Private_fcn2 must not begin in uppercase.
B: Warning W9131: Private function name Private_fcn2 must end with an underscore.
1 27 void private_fcn3_(int);
1 28 void Private_fcn4_(int);
------- A
A: Warning W9131: Private function name Private_fcn4_ must not begin in uppercase.
1 29
1 30 protected:
1 31 void protected_fcn(int);
1 32
1 33 public:
1 34 void public_fcn(int);
1 35
1 36 inline int wrong(void);
------- A
A: Warning W9232: Do NOT use inline within a class definition. (1)
1 37 int one_liner(void);
1 38 int two_liner(void);
1 39 };
------- ABCD
A: Warning W9251: Class Bleep needs a default constructor.
B: Warning W9251: Class Bleep needs a copy constructor.
C: Warning W9252: Class Bleep needs an operator=(Bleep&).
D: Warning W9254: Class Bleep needs a destructor.
1 40
================================================================
Resume checking xyz_test.c
24
25
26 inline int Bleep::wrong()
27 {
28 int x = 2;
29 return (x*x);
30 }
------- A
A: Warning W9231: Function wrong is too long to be inlined.
31
32 inline int Bleep::one_liner()
33 {
34 return private_mem3_;
35 }
36
37 inline int Bleep::two_liner()
38 {
39 int x = 2;
40 return (x*x);
41 }
------- A
A: Warning W9231: Function two_liner is too long to be inlined.
42
43
44 typedef double Volts;
------- A
A: Warning W9282: Define typedef name Volts in a base class.
45 enum Modulation { AM, FM, PCM };
------- A
A: Warning W9293: Define enum Modulation in a base class.
46 enum { k1000, k2000 };
------- AB
A: Warning W9422: This enumeration needs an enum type name.
B: Warning W9293: Define enum in a base class.
47 class ABC glob;
48 oldstyle();
------- A
A: Warning W9441: Function oldstyle needs an explicit return type.
49
50
51 class Bloop : virtual Bleep
------- A
A: Warning W9271: Do NOT use virtual base classes.
52 {
------- AB
A: Warning W9121: Class names must begin with "XYZ_"
B: Warning W9211: Definition of class Bloop belongs in a header file.
53 int foo; /* old-style C comment */
------- A BCD
A: Warning W9131: Private data member name foo must end with an underscore.
B: Warning W9221: Public section must come first in class Bloop.
C: Warning W9281: Declare foo using a typedef name, not a basic C type.
D: Warning W9411: Use // comments, not /*...*/ comments.
54
55 public:
56 typedef int count;
57 enum Greek { Alpha, Beta, Gamma, Delta, Epsilon };
58
59 constructor Bloop(); // default constructor
60 constructor Bloop( Bloop & ); // copy constructor
61 constructor Bloop( int x );
62 constructor Bloop( float y );
63 destructor ~Bloop();
64
65 Bloop & operator=( Bloop & );
66 Bloop & operator|( Bloop & );
------- A
A: Warning W9312: Bloop::operator|() should not return an object.
67 count BadParm1( Bloop * );
------- A
A: Warning W9311: Declare parameter #1 to be a reference to Bloop.
68 void BadParm2( Bleep );
------- A
A: Warning W9311: Declare parameter #1 to be a reference to Bleep.
69 virtual count bar( ABC ) const;
------- A B
A: Warning W9311: Declare parameter #1 to be a reference to ABC.
B: Warning W9316: Constant member functions should be avoided.
70 friend Bloop& operator[]( int );
------- AB
A: Warning W9261: operator[] should not be a friend.
B: Warning W9314: Function Bloop::operator[]() should not return an object.
71 friend void amigo();
------- A
A: Warning W9261: Do NOT declare friend functions.
72 friend class ABC;
------- A
A: Warning W9262: Do NOT declare friend classes.
73 ABC makeABC( int, const Bleep & );
------- ABC
A: Warning W9315: Reference parameters must come first.
B: Warning W9317: Parameter #2 should not be const.
C: Warning W9314: Function Bloop::makeABC() should not return an object.
74 };
------- AB
A: Warning W9253: Class Bloop has too many constructors (limit = 3).
B: Warning W9255: Destructor Bloop::~Bloop() must be virtual.