在嵌入式C代码上重新定义可长期使用的代码分析工具 [英] Redefine short long to use code analysis tools on embedded c code

查看:76
本文介绍了在嵌入式C代码上重新定义可长期使用的代码分析工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SourceTrails( https://www.sourcetrail.com/)来从MPLAB CX8编译器分析嵌入式c.这并不是完全没有问题,因为编译器使用了C标准中未提供的许多自定义功能.

其中之一是使用 short long 表示全局包含中的24位变量,例如:

  extern volatile无符号短长TBLPTR; 

SourceTrail(使用clang)显示此错误: 无法与以前的"short"组合声明说明符.

仅出于分析目的,我想在全局包含顶部指定类似的内容:

  #define短长"长 

但是很明显,这失败了!

我可能必须执行搜索和替换,但是如果有一个更简单的方法,那会很棒吗?

解决方案

您可以使用类似以下内容的

  #define short int 

short long 变量现在将为 long ,至少在诸如 gcc clang 之类的主流编译器中./p>

任何 short 变量现在将为 int ,其副作用是 short int 声明现在将导致无效组合错误.


https://www.sourcetrail.com/) to analyze embedded c from the MPLAB CX8 compiler. It's not entirely trouble-free, as the compiler uses a number of custom features, not found in the C standard.

One of these is the use of short long to indicate 24-bit variables in global includes, such as:

extern volatile unsigned short long     TBLPTR;

SourceTrail (using clang) shows this error: cannot combine with previous "short" declaration specifier.

For the analysis only, I'd like to specify something like on the top of the global include:

#define "short long" long

but obviously, this fails!

I might have to perform a search and replace, but it would be great if there were a simpler method?

解决方案

You can use something like:

#define short int

short long variables will now be long, at least in mainstream compilers like gcc and clang.

Any short variables will now be int, the side effect is that short int declarations will now cause invalid combination error.


The solution found by the OP was to use #define short which will effectively remove short from the type declaration making it long.

The side effect is that variables declared short will have no type or storage class, and as such, will default to int.

In compilers like clang or gcc the type int long will default to long effectively making both solutions possible, minding the different side effects.

这篇关于在嵌入式C代码上重新定义可长期使用的代码分析工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆