MPC5748G开发笔记----- S32DS 消除warning: unused variable

S32DS 消除warning: unused variable


前言

在用S32DS开发编译程序时,很多警告把要提示的重要信息淹没了,为了提高开发效率可以过滤掉没用的警告信息。


一、原因分析warning: unused variable

产生该警告的原因是程序中定义的变量没有使用。
在这里插入图片描述

二、解决方法

1.用UNUSED宏

https://stackoverflow.com/questions/3599160/how-to-suppress-unused-parameter-warnings-in-c

#define UNUSED(x) (void)(x)
You can use this macro for all your unused parameters. (Note that this works on any compiler.)

For example:

void f(int x) {
    UNUSED(x);
    ...
}

2.添加unused属性告诉编译器

代码如下(示例):

You can use gcc/clang's unused attribute, however I use these macros in a header to avoid having gcc specific attributes all over the source, also having __attribute__ everywhere is a bit verbose/ugly.

#ifdef __GNUC__
#  define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
#else
#  define UNUSED(x) UNUSED_ ## x
#endif

#ifdef __GNUC__
#  define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_ ## x
#else
#  define UNUSED_FUNCTION(x) UNUSED_ ## x
#endif
Then you can do...

void foo(int UNUSED(bar)) { ... }
I prefer this because you get an error if you try use bar in the code anywhere so you can't leave the attribute in by mistake.

and for functions...

3.禁用该消息提示

考虑到该警告对程序基本没有不良不影响,因此利用编译指令直接去除该警告。

#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"

总结

采用第三种方法简单粗暴有效,节省的时间去享受美好的生活不香吗?效果如下,世界顿时安静了。
在这里插入图片描述

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
根据引用\[1\]中的信息,当在S32DS编译项目时出现"arm-none-eabi-gcc: command not found"的错误时,可以尝试以下解决方法。首先,前往Cross_Tools/gcc-arm-none-eabi_4_9/bin目录,检查是否存在arm-none-eabi-gcc文件。如果存在,尝试运行"./arm-none-eabi-gcc"命令,如果出现"./arm-none-eabi-gcc: No such file or directory"的错误,说明缺少共享库。可以通过运行"sudo apt install lib32z1"命令来安装缺少的共享库,解决该问题。 另外,根据引用\[2\]中的信息,如果在使用交叉编译器时出现类似"arm-linux-gcc: Command not found"的错误,可以尝试以下解决方法。首先,检查是否正确设置了交叉编译器的路径,可以使用"arm-linux-gcc -v"命令来检查。如果路径设置正确,但仍然无法找到arm-linux-gcc命令,可以尝试使用超级用户权限的shell,并使用"export PATH=$PATH:/usr/local/arm/2.95.3/bin"命令设置环境变量。然后进入到kernel目录,运行"make zImage"命令,应该能够找到arm-linux-gcc了。 综上所述,当在S32DS中出现"arm-none-eabi-gcc: command not found"的错误时,可以尝试安装缺少的共享库或者检查交叉编译器的路径设置。如果问题仍然存在,可以尝试使用超级用户权限的shell并设置环境变量来解决该问题。 #### 引用[.reference_title] - *1* [ubuntu18版本使用S32DS遇到的问题](https://blog.csdn.net/Mr0cheng/article/details/84290504)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [arm-linux-gcc: Command not found 问题解析](https://blog.csdn.net/sdwuyulunbi/article/details/6152437)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值