测试平台:ubuntu 12.04.4 64bit
硬件都是一样的哈!
首先安装:gcc(也许系统自带,也许没有,暂时不管)
sudo apt-get install build_essential
然后再安装clang
sudo apt-get install clang-3.3 clang-3.3-doc
用vim编辑测试代码:
(推荐一篇vim+completeme的配置文章,猛击这里:)
(肯定是有问题的哈)
#include<stdio.h>
int main()
{
int hello=12;
if(hell==12)
{
printf("hello is %d",hello);
}
else if(hel==12)
{
printf("hello world!")
}
return 0;
}
來看看两个报错情况:
首先是clang
hello.c:5:5: error: use of undeclared identifier 'hell'; did you mean 'hello'?
if(hell==12)
^~~~
hello
hello.c:4:6: note: 'hello' declared here
int hello=12;
^
hello.c:9:10: error: use of undeclared identifier 'hel'
else if(hel==12)
^
hello.c:11:25: error: expected ';' after expression
printf("hello world!")
^
;
3 errors generated.
然后是gcc的
hello.c: 在函数‘main’中:
hello.c:5:5: 错误: ‘hell’未声明(在此函数内第一次使用)
hello.c:5:5: 附注: 每个未声明的标识符在其出现的函数内只报告一次
hello.c:9:10: 错误: ‘hel’未声明(在此函数内第一次使用)
hello.c:12:2: 错误: expected ‘;’ before ‘}’ token
可以看出clang的报错精确程度确实比gcc高些
所以;life is short ,use clang