编译器选项-(工作总结)

1.编译器选项

本文总结在编译器中使用的变量:

2.编译器

2.1 Mingw 和 GUN 相关

部分 含义 说明
-W 警告(Warning)选项前缀 所有控制警告的编译器选项都以 -W 开头。
dangling-else 特定的警告名称 指代代码中可能引起歧义的“悬挂 else”问题。
-Wno-error= 操作指令 不将指定的警告升级为错误。警告仍会产生,但不会中断编译。
按照 C/C++ 标准规则,else 会与最近的那个尚未配对的 if 配对(即与内层的 if (condition2) 配对)。但代码的缩进可能误导读者以为 else 与外层的 if 配对,这正是警告要提醒你的。

// 示例代码:存在 “dangling else” 歧义
if (condition1)
    if (condition2)
        printf("Both true.\n");
else // 这个 else 属于哪个 if?编译器会警告。
    printf("This indentation is misleading!\n");

// 编译时,GCC/Clang 默认会产生类似警告:
// warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]

posted @ 2026-01-23 17:21  退休人生  阅读(3)  评论(0)    收藏  举报