c - 如何删除特定的警告 gcc
问题描述
我有一个特定的警告,我想删除/隐藏然后在之后启用它。您知道如何在不删除所有其他警告的情况下做到这一点吗?
这是我收到的警告
warning: enumeration value 'EtatCCSortie' not handled in switch [-Wswitch]
而且我不需要在交换机中实际使用该状态(它是一个状态机)。我有办法不再收到此警告,即通过将状态添加到开关中,如下所示:
while (etatsImprimanteCasImpressionPeriodique != EtatIPSortie)
{
switch (etatsImprimanteCasChangementCartouche)
{
....
case EtatCCSortie:
break;
但我不必添加它,因为它永远不会执行(而!=)。这就是为什么我正在寻找一种方法来禁用此特定警告,然后在此切换后启用它。
Ps:我知道警告的重要性,我只需要一种方法来删除它。
解决方案
使用诊断编译指示:
enum somenum {
EtatIPSortie,
EtatCCSortie,
};
int etatsImprimanteCasImpressionPeriodique;
enum somenum etatsImprimanteCasChangementCartouche;
void func() {
while (etatsImprimanteCasImpressionPeriodique != EtatIPSortie)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch"
switch (etatsImprimanteCasChangementCartouche)
{
case EtatCCSortie:
break;
}
#pragma GCC diagnostic pop
}
}
推荐阅读
- c - 如何在文件和控制台中存储、写入、读取多字节字符(字符串)
- palantir-foundry - 如何为 CURRENT_TIMESTAMP 配置 Code Workbook 的时区?
- flutter - Flutter 将文本添加到 TextField 控制器中
- joomla - 安排 Joomla 网站离线
- django - 如何避免 Django 模板中的重复数据
- debugging - 使用 Telerek Just Decompile 重新创建 .NET 源项目L:无法正常调试
- python - Mongoengine:发生异常:ServerSelectionTimeoutError
- python - 如果键不是数字,如何删除 JSON 中的元素?
- javascript - 在已触发 js 函数的 div 中添加一个元素(输入)
- sprite-kit - 如何使 SKScene 的背景透明,以便在 ZStack 中分层?