为文字字符溢出启用 gcc 警告

Enable gcc warning for literal char overflow

在 gcc 中,即使 -Wall 开启,我也没有收到以下警告:char x = 0xff;

但是 -pedantic 我愿意。

有没有办法在不使用 pedantic 和获取其他 pedantic 警告的情况下打开此警告?

我不确定是否还有另一个 FLAG,如果你不想使用 -pedantic/-Wpedantic,你可以尝试这样的方法:

error: conversion to ‘char’ alters ‘int’ constant value [-Werror=conversion]
 char x = 0xff;
          ^

如果是,则执行:

gcc -Wconversion