********************************************************************************/
在大概看完了上述资料后,就可以把这个工具正式用于我们的程序了。
将该工具集成到VC++里是最常用到的,在网上也可以找到很多相关资料。
现在我简单的讲一下将它集成到Editpuls里,因为我比较喜欢用纯文本编辑器写代码,呵呵!
还是先看看网上的关于这方面的资料:-P
http://xyzboard.com/?q=node/58
现在我写下我的经验:
在上述资料里有一些要修改的地方。
首先要注意Unix下xargs命令的使用。一定要给全路径!
比如我的是这样设参数项的:
$(FilePath) -name *.c -o -name *.cpp | D:\UnxUtils\usr\local\wbin\xargs
D:\Sources\PC-Lint\lint-nt -i"D:\UnxUtils\usr" -u D:\Sources\PC-Lint\std.lnt
D:\Sources\PC-Lint\env-vc6.lnt -w
也就是说xargs后的路径要给全。。。。
再有就是在编写std.lnt文件的时候要注意的,这个是我的std.lnt文件:
D:\Sources\PC-Lint\co-msc60.lnt
D:\Sources\PC-Lint\lib-w32.lnt
D:\Sources\PC-Lint\options.lnt -si4 -sp4
-i"D:\Microsoft Visual Studio 8;D:\Microsoft Visual Studio 8\VC\include"
-wlib(0)
最后的-wlib(0)是取消对编译器库文件的审查,这个是相当重要的一个参数。如果
你只是想审查自己的代码的话,请加上这个参数。不然,就会对编译器的库函数也
进行审查。。。。想看看库文件的可以研究一下,呵呵!
好了,现在你就可以对自己的代码进行摸底咯~~~~
下面这个是我的一个数据结构的实验:Complex的代码
/**********************************************************************
File name: Complex.h
Function: The description of complex class
Platform: Win Xp SP2
Compiler & Linker: CL.exe 8.0 (in Visual Studio 2005 SDK)
Programmer: 88250
Complete date: September 7, 2006 Version: 1.0
Blog: http://DL88250.ynutx.net
E-mail: DL88250@gmail.com
QQ: 845765 or 316281008
**********************************************************************/
#i nclude <iostream>
using namespace std;
class complex
{
public: // public interface
complex(double r, double i); // constructor
void assign(void); // user input to define a complex
// overload operators to friend functions
friend complex operator + (complex &c1, complex &c2);
friend complex operator - (complex &c1, complex &c2);
friend complex operator * (complex &c1, complex &c2);
friend complex operator / (complex &c1, complex &c2);
friend ostream& operator << (ostream &out, complex x);
private:
double real;
double imag;
};
/**********************************************************************
File name: Complex.h
Function: A simple complex calculator demo
Platform: Win Xp SP2
Compiler & Linker: CL.exe 8.0 (in Visual Studio 2005 SDK)
Programmer: 88250
Complete date: September 7, 2006 Version: 1.0
Blog: http://DL88250.ynutx.net
E-mail: DL88250@gmail.com
QQ: 845765 or 316281008
**********************************************************************/
#i nclude "Complex.h"
complex::complex(double r = 0.0, double i = 0.0)
{
real = r;
imag = i;
return;
}
void complex::assign(void)
{
cout << "Please input the real part : " << endl;
cin >> real;
cout << "Please input the imaginary part: " << endl;
cin >> imag;
return;
}
ostream& operator << (ostream &out, complex x)
{
if (x.imag < 0)
{
return (out << x.real << " + " << "(" << x.imag << ")" << "i" <<
endl);
}
else
{
return (out << x.real << " + " << x.imag << "i" << endl);
}
}
complex operator + (complex &c1, complex &c2)
{
return complex(c1.real + c2.real, c1.imag + c2.imag);
}
complex operator - (complex &c1, complex &c2)
{
return complex(c1.real - c2.real, c1.imag - c2.imag);
}
complex operator * (complex &c1, complex &c2)
{
return complex((c1.real * c2.real - c1.imag * c2.imag)
,(c1.real * c2. imag + c2.real * c1.imag));
}
complex operator / (complex &c1, complex &c2)
{
double denominator = c2.real * c2.real + c2.imag * c2.imag;
return complex((c1.real * c2.real + c1.imag * c2.imag) / denominator
,(c1.imag * c2.real - c1.real * c2.imag) /
denominator);
}
int main(void)
{
complex c1(5, 4), c2(2, 10);
cout << "c1 = " << c1;
cout << "c2 = " << c2;
cout << "c1 + c2 = " << c1 + c2;
cout << "c1 - c2 = " << c1 - c2;
cout << "c1 * c2 = " << c1 * c2;
c1.assign();
cout << "Current c1 = " << c1;
c2.assign();
cout << "Current c2 = " << c2;
cout <<"c1 / c2 = " << c1 / c2;
return 0;
}
现在用PC-Lint审查一下:
PC-lint for C/C++ (NT) Ver. 8.00e, Copyright Gimpel Software 1985-2001
--- Module: D:\Sources\C++\DataStructure\Exp1\Complex.cpp
};
D:\Sources\C++\DataStructure\Exp1\Complex.h(33): error 1712: (Info -- default co
nstructor not defined for class 'complex')
*/
D:\Sources\C++\DataStructure\Exp1\Complex.h(70): error 783: (Info -- Line does n
ot end with new-line)
}
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(44): error 1746: (Info -- paramete
r 'x' in function 'operator<<(std::basic_ostream<char,std::char_traits<char>> &,
complex)' could be made const reference)
}
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(49): error 1764: (Info -- Referenc
e parameter 'c1' (line 46) could be declared const ref)
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(46): error 830: (Info -- Location
cited in prior message)
}
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(49): error 1764: (Info -- Referenc
e parameter 'c2' (line 46) could be declared const ref)
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(46): error 830: (Info -- Location
cited in prior message)
}
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(54): error 1764: (Info -- Referenc
e parameter 'c1' (line 51) could be declared const ref)
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(51): error 830: (Info -- Location
cited in prior message)
}
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(54): error 1764: (Info -- Referenc
e parameter 'c2' (line 51) could be declared const ref)
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(51): error 830: (Info -- Location
cited in prior message)
}
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(60): error 1764: (Info -- Referenc
e parameter 'c1' (line 56) could be declared const ref)
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(56): error 830: (Info -- Location
cited in prior message)
}
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(60): error 1764: (Info -- Referenc
e parameter 'c2' (line 56) could be declared const ref)
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(56): error 830: (Info -- Location
cited in prior message)
}
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(68): error 1764: (Info -- Referenc
e parameter 'c1' (line 62) could be declared const ref)
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(62): error 830: (Info -- Location
cited in prior message)
}
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(68): error 1764: (Info -- Referenc
e parameter 'c2' (line 62) could be declared const ref)
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(62): error 830: (Info -- Location
cited in prior message)
complex c1(5, 4), c2(2, 10);
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(72): error 747: (Info -- Significa
nt prototype coercion (arg. no. 1) int to double)
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(72): error 747: (Info -- Significa
nt prototype coercion (arg. no. 2) int to double)
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(72): error 747: (Info -- Significa
nt prototype coercion (arg. no. 1) int to double)
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(72): error 747: (Info -- Significa
nt prototype coercion (arg. no. 2) int to double)
}
D:\Sources\C++\DataStructure\Exp1\Complex.cpp(88): error 783: (Info -- Line does
not end with new-line)
--- Global Wrap-up
error 1754: (Info -- Expected symbol 'operator*=' to be declared for class 'com
plex')
error 1754: (Info -- Expected symbol 'operator+=' to be declared for class 'com
plex')
error 1754: (Info -- Expected symbol 'operator-=' to be declared for class 'com
plex')
error 1754: (Info -- Expected symbol 'operator/=' to be declared for class 'com
plex')
error 900: (Note -- Successful completion, 28 messages produced)
请按任意键继续. . .
哎。。。。问题好多。。。。
改了下代码:
/**********************************************************************
File name: Complex.h
Function: The description of complex class
Platform: Win Xp SP2
Compiler & Linker: CL.exe 8.0 (in Visual Studio 2005 SDK)
Programmer: 88250
Complete date: September 7, 2006 Version: 1.0
Blog: http://DL88250.ynutx.net
E-mail: DL88250@gmail.com
QQ: 845765 or 316281008
**********************************************************************/
#i nclude <iostream>
using namespace std;
class complex
{
public: // public interface
complex(double r, double i); // constructor
complex(void); // void constructor
void assign(void); // user input to define a complex
// overload operators to friend functions
friend complex operator + (const complex &c1,
const complex &c2);
friend complex operator - (const complex &c1,
const complex &c2);
friend complex operator * (const complex &c1,
const complex &c2);
friend complex operator / (const complex &c1,
const complex &c2);
friend ostream& operator << (ostream &out, const complex &x);
private:
double real;
double imag;
};
/**********************************************************************
File name: Complex.h
Function: A simple complex calculator demo
Platform: Win Xp SP2
Compiler & Linker: CL.exe 8.0 (in Visual Studio 2005 SDK)
Programmer: 88250
Complete date: September 7, 2006 Version: 1.0
Blog: http://DL88250.ynutx.net
E-mail: DL88250@gmail.com
QQ: 845765 or 316281008
**********************************************************************/
#i nclude "Complex.h"
complex::complex(void)
{
real = 0;
imag = 0;
return;
}
complex::complex(double r = 0.0, double i = 0.0)
{
real = r;
imag = i;
return;
}
void complex::assign(void)
{
cout << "Please input the real part : " << endl;
cin >> real;
cout << "Please input the imaginary part: " << endl;
cin >> imag;
return;
}
ostream& operator << (ostream &out, const complex &x)
{
if (x.imag < 0)
{
return (out << x.real << " + " << "(" << x.imag << ")" << "i" <<
endl);
}
else
{
return (out << x.real << " + " << x.imag << "i" << endl);
}
}
complex operator + (const complex &c1, const complex &c2)
{
return complex(c1.real + c2.real, c1.imag + c2.imag);
}
complex operator - (const complex &c1, const complex &c2)
{
return complex(c1.real - c2.real, c1.imag - c2.imag);
}
complex operator * (const complex &c1, const complex &c2)
{
return complex((c1.real * c2.real - c1.imag * c2.imag)
,(c1.real * c2. imag + c2.real * c1.imag));
}
complex operator / (const complex &c1, const complex &c2)
{
double denominator = c2.real * c2.real + c2.imag * c2.imag;
return complex((c1.real * c2.real + c1.imag * c2.imag) / denominator
,(c1.imag * c2.real - c1.real * c2.imag) /
denominator);
}
int main(void)
{
complex c1(5.0, 4.0), c2(2.0, 10.0);
cout << "c1 = " << c1;
cout << "c2 = " << c2;
cout << "c1 + c2 = " << c1 + c2;
cout << "c1 - c2 = " << c1 - c2;
cout << "c1 * c2 = " << c1 * c2;
c1.assign();
cout << "Current c1 = " << c1;
c2.assign();
cout << "Current c2 = " << c2;
cout <<"c1 / c2 = " << c1 / c2;
return 0;
}
现在好多了:
PC-lint for C/C++ (NT) Ver. 8.00e, Copyright Gimpel Software 1985-2001
--- Module: D:\Sources\C++\DataStructure\Exp1\Complex.cpp
--- Global Wrap-up
error 1754: (Info -- Expected symbol 'operator*=' to be declared for class 'com
plex')
error 1754: (Info -- Expected symbol 'operator+=' to be declared for class 'com
plex')
error 1754: (Info -- Expected symbol 'operator-=' to be declared for class 'com
plex')
error 1754: (Info -- Expected symbol 'operator/=' to be declared for class 'com
plex')
D:\Microsoft Visual Studio 8\VC\include\xutility(873): error 628: (Warning -- no
argument information provided for function 'std::__is_base_of()' (line 873, fil
e D:\Microsoft Visual Studio 8\VC\include\xutility))
error 900: (Note -- Successful completion, 5 messages produced)
请按任意键继续. . .
关于剩下的问题可以参看PC-Lint目录下的msg.txt文件,里面有详细的解释。。。。
哎。。。。闪人咯~~~~
:-P








