由于LARGEADDRESSAWARE检测指针算术 [英] Detect pointer arithmetics because of LARGEADDRESSAWARE

查看:121
本文介绍了由于LARGEADDRESSAWARE检测指针算术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将应用程式切换为LARGEADDRESSAWARE。要注意的问题之一是指针运算,因为指针差异不能再表示为有符号32b。

I would like to switch my application to LARGEADDRESSAWARE. One of issues to watch for is pointer arithmetic, as pointer difference can no longer be represented as signed 32b.

有一些方法可以自动找到指针减法的所有实例

Is there some way how to find automatically all instances of pointer subtraction in a large C++ project?

如果没有,是否有一些最小努力手动或半自动方法如何实现这一目标?

If not, is there some "least effort" manual or semi-automatic method how to achieve this?

推荐答案

由于我们的代码已经编译GCC,我想也许最快的方法可能是:

As our code already compiles with GCC, I think perhaps the fastest way might be:


  • 创建GCC

  • 创建GCC的自定义修改,以便在检测到指针减法时打印警告(或错误)

  • 构建项目并收集有关指针减法的所有警告

以下是需要对GCC进行的更改的大纲:

Here is the outline of changes which need to be done to GCC for this:

将您的警告添加到:


  • c-typeck.c c $ c> pointer_diff function)

  • cp / typeck.c( pointer_diff function) li>
  • c-typeck.c (pointer_diff function)
  • cp/typeck.c (pointer_diff function).

除了直接检测指针减法,另一件事情可以是检测首先将指针转换为整数类型然后减去它们的情况。这可能更困难,取决于你的代码如何结构,在out case regexp搜索(。* intptr_t)。 - 。 - (。* intptr_t)工作得很好。

Besides of directly detecting pointer subtraction, another thing to do can be to detect cases where you first convert pointers to integral types and then subtract them. This may be more difficult depending on how is your code structured, in out case regexp search for (.*intptr_t).-.-(.*intptr_t) has worked quite well.

这篇关于由于LARGEADDRESSAWARE检测指针算术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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