关于gcc的一点小人性化提示
2014-10-27 05:44
302 查看
现在对于大多数平台的C编译器来说都会有很多种选择,而gcc和clang无疑是2个非常优秀的C编译器。当然他们也不只是C编译器。我最近用clang的比较多,原因有很多。不过一些小的细节很让我喜欢,比如OS X系统中,clang的编译器警告或错误提示是以彩色文本醒目打印出来的。
而gcc则无论如何打印的颜色都一样(我不知道是否有什么设置可以改变这一点)。
但是gcc也有其人性化的一点,就是在某些比较隐晦的错误时,会有更友好的提示。比如标签后不能直接写声明这种情况,2种编译器的结果如下:
clang编译结果:
apple@kissAir: c_src$clang -std=c11 -Wall -O3 -g0 -o x x.c
x.c:12:2: error: expected expression
int x = 10;
^
1 error generated.
gcc编译结果:
apple@kissAir: c_src$gcc -std=c11 -Wall -O3 -g0 -o x x.c
gcc: warning: couldn't understand kern.osversion '14.0.0
x.c: In function 'main':
x.c:12:2: error: a label can only be part of a statement and a declaration is not a statement
int x = 10;
^
x.c:12:6: warning: unused variable 'x' [-Wunused-variable]
int x = 10;
^
可以很清楚的看出,前者只是简单一句模凌两可的提示,让初学者丈二和尚摸不着头脑;不过后者解释的就很清楚了,这是不是让初学乍到的程序猿们感觉很温馨呢?
而gcc则无论如何打印的颜色都一样(我不知道是否有什么设置可以改变这一点)。
但是gcc也有其人性化的一点,就是在某些比较隐晦的错误时,会有更友好的提示。比如标签后不能直接写声明这种情况,2种编译器的结果如下:
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <math.h> #include <unistd.h> int main(void) { int i = 0; puts("hello world!"); LAB: int x = 10; printf("now is %d\n",i++); sleep(3); goto LAB; return 0; }
clang编译结果:
apple@kissAir: c_src$clang -std=c11 -Wall -O3 -g0 -o x x.c
x.c:12:2: error: expected expression
int x = 10;
^
1 error generated.
gcc编译结果:
apple@kissAir: c_src$gcc -std=c11 -Wall -O3 -g0 -o x x.c
gcc: warning: couldn't understand kern.osversion '14.0.0
x.c: In function 'main':
x.c:12:2: error: a label can only be part of a statement and a declaration is not a statement
int x = 10;
^
x.c:12:6: warning: unused variable 'x' [-Wunused-variable]
int x = 10;
^
可以很清楚的看出,前者只是简单一句模凌两可的提示,让初学者丈二和尚摸不着头脑;不过后者解释的就很清楚了,这是不是让初学乍到的程序猿们感觉很温馨呢?
相关文章推荐
- 关于gcc的一点小人性化提示
- 关于gcc的一点小人性化提示
- 关于gcc的一点小人性化提示
- 关于vector删除操作的一点提示。
- 关于在命令提示行中javac命令不能运行的一点建议
- 给初学者关于eclilse汉化及tomcat错误的一点提示
- 关于Google Body提示"WebGL is not initializing properly"的一点经验
- 关于类成员函数中静态变量的一点提示
- 关于Java类设计中信息隐蔽原则的一点提示
- GCC扩展内联汇编关于寄存器的一点问题
- 关于Java类设计中信息隐蔽原则的一点提示
- 关于flash嵌入的一点东西
- 关于cnblogs上面功能改进的一点建议
- 关于如何jar的一点总结 (转自:javaresearch yedongshu2001 原创)
- 关于html上脚本语言的一点小释疑
- 关于用VC,VB进行图像数据(二进制大对象)存储数据库的一点心得
- 关于定时关闭询问对话框的一点体会
- 关于Windows下ShellCode编写的一点思考
- 关于系统分析师考试的一点感慨
- 关于黄家驹的一点想法