ARM Compiler 5
"main.cpp", line 6: Warning: #1293-D: assignment in condition
if (a = b) {
^
ARM Compiler 6
main.cpp:6:11: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
if (a = b) {
~~^~~
main.cpp:6:11: note: place parentheses around the assignment to silence this warning
if (a = b) {
^
( )
main.cpp:6:11: note: use '==' to turn this assignment into an equality comparison
if (a = b) {
^
==
GCC 4.9你可以从不同的输出看到,ARM编译器6不仅告诉你代码中哪里有错,而且给出了种不同的方法去修正这个错误,警告信息引用了整行代码并且高亮了用户需要注意的部分
main.cpp: In function ‘int main()’:
main.cpp:6:14: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
ARM Compiler 5
"main.cpp", line 5: Error: #144: a value of type "const int *" cannot be used to initialize an entity of type "const float *"
std::vector<float>::const_iterator i = input.begin();
^
ARM Compiler 6
main.cpp:5:40: error: cannot initialize a variable of type 'std::vector<float>::const_iterator' (aka 'const float *') with an rvalue of type 'const_iterator' (aka 'const int *')
'std::vector<float>::const_iterator i = input.begin();
^ ~~~~~~~~~~~~~
GCC 4.9ARM编译器5和6产生的错误信息是自解释,并且明确告诉用户如何去修复这个问题:模板类型的不匹配的问题在错误信息中明确指出,箭头号明确指出了错误点。相比之下,GCC产生了100多行神仙才能看得懂的错误信息。
main.cpp: In function ‘int sum_vector(const std::vector<int>&)’:
main.cpp:5:56: error: conversion from ‘std::vector<int>::const_iterator {aka __gnu_cxx::__normal_iterator<const int*, std::vector<int> >}’ to non-scalar type ‘std::vector<float>::const_iterator {aka __gnu_cxx::__normal_iterator<const float*, std::vector<float> >}’ requested
main.cpp:7:26: error: no match for ‘operator!=’ in ‘i != (& input)->std::vector<_Tp, _Alloc>::end<int, std::allocator<int> >()’
main.cpp:7:26: note: candidates are:
In file included from /usr/include/x86_64-linux-gnu/c++/4.7/./bits/c++allocator.h:34:0,
from /usr/include/c++/4.7/bits/allocator.h:48,
…
(additional 98 lines following)
ARM Compiler 6总结
main.cpp:8:14: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
LOG_WARNING(123);
~~~~~~~~~~~~^~~
main.cpp:5:45: note: expanded from macro 'LOG_WARNING'
#define LOG_WARNING(MESSAGE) LOG("Warning", MESSAGE)
^
main.cpp:3:64: note: expanded from macro 'LOG'
#define LOG(PREFIX, MESSAGE) fprintf(stderr, "%s: %s", PREFIX, MESSAGE)
^
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |