3

我正在尝试修复构建错误。

有问题的代码行如下:

fprintf(crashLog, "RIP: %lX\n", context->uc_mcontext.gregs[REG_RIP]);

因此:

  • gregs 的类型为 gregset_t
  • gregs[i] 是 greg_t 类型

现在这段代码(用于生成核心转储和堆栈跟踪)已经工作了很长时间,但最近,GCC 4.7.3(Ubuntu 13.04)开始拒绝它:

error: format ‘%lX’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘greg_t {aka long long int}’ [-Werror=format]

美好的。所以我将违规行更改为:

fprintf(crashLog, "RIP: %llX\n", context->uc_mcontext.gregs[REG_RIP]);

但是 GCC 4.6.3 (Ubuntu 12.04) 反而抱怨:

error: format ‘%llX’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘greg_t {aka long int}’ [-Werror=format]

在这部分代码中已经有用于各种寄存器的 ifdef,所以我可以添加另一个,但是有没有一种很好的干净方法来做到这一点(尤其是不需要额外的 ifdef)?

4

0 回答 0