关键词:MDK平台;C程序;error & warning
1.error: #260-D: explicit type is missing(“int” assumed)
warning: type specifier missing, defaults to ‘int’
注意函数参数(输入输出返回值)的类型,无返回值加void
2.error: L6200E: Symbol XXXXXX multiply defined (by xxxxx.o and yyyyy.o)
xxxxx.c与yyyyy.c文件或对应.h文件中有重复定义函数
3.error: #147-D: declaration is incompatible with “xxxxxx”(declared at line xx of “zz\zz\xx.h”)
c文件中的函数名及参数类型必须和h文件中一致(比如:在usart.h中有void uart_init(u32 bound); usart.c中错写为void uart_init(void))
4.warning: #940-D: missing return statement at end of non-void function “AB_C”
返回非空的函数“AB_C”的结尾缺少返回值
例:
不规范代码:
int AB_C(void)
{
if(a==1) return 1;
else if(a==2) return 2;
else return 3;
}
规范代码:
int AB_C(void)
{
int b;
if(a==1) b=1;
else if(a==2) b=2;
else b=3;
return b;
}
第一段代码确实简单一些,但因为没有一个固定的变量b来过渡返回值,导致编译器没有识别到返回值,所以warning无返回值。
5.warning: #186-D: pointless comparison of unsigned integer with zero
无符号整型与零相做比较无意义。
不规范代码:
u8 temp;
if(temp<0)
{...}
规范代码:
float temp;
if(temp<0)
{...}
u8为8位无符号整型,没有正负之分,所以与零比较没有意义。而float是有符号类型,所以没问题。