【发布时间】:2014-01-10 17:27:34
【问题描述】:
我使用提供内联函数的头文件。就 GCC -Wconversion 检查而言,这些函数并不总是保存。
现在我想对 我的代码 使用 -Wconversion 检查,但想抑制我收到的包含文件的警告。 编辑:当我只是将转换检查添加到编译器选项中时,我会得到诊断,省略 -Wconversion 会给我一个干净的编译器运行。
对应于this question,我用一些pragma包围了include:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#include <lpc177x_8x_crc.h>
#pragma GCC diagnostic pop
不幸的是,这不会抑制警告。
warning: conversion to 'int32_t' from 'uint32_t' may change the sign of the result [-Wsign-conversion]
为了方便检查,如果您没有可用的 CMSIS,您甚至可以试试这个:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
int32_t foo(void)
{
uint32_t result;
return result;
}
#pragma GCC diagnostic pop
编译器命令行参数是:
arm-none-eabi-gcc.exe -mthumb -Wshadow -Winit-self -Wredundant-decls -Wcast-align -Wunreachable-code -W -Wextra -Wall -Wformat=0 -Wconversion -g -O0 -ffunction-sections -fdata-sections -g3 -mcpu=cortex-m3 -c foo.c -o foo.o
我使用 arm-none-abi-gcc 版本:
gcc version 4.7.3 20121207 (release) [ARM/embedded-4_7-branch revision 194305] (GNU Tools for ARM Embedded Processors)
【问题讨论】:
-
我在 Linux 上尝试使用 gcc 4.8,但无法重现此问题。您能否提供您收到的确切消息?会不会是另一个,与 -Wconversion 无关?
标签: c++ c gcc gcc-warning integer-overflow