MDK error&waring Summary

关键词: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是有符号类型,所以没问题。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值