【记录】gcc -Wall 警告意思

· · 个人记录

Code::blcoks - Setting - Compiler… - Other compiler options - 输入 -Wall - OK 。

Dev-c++ - Tools - Setting - Warnings - Show most warnings (-Wall) - Yes 。

  1. no return statement in function returning non-void [-Wreturn-type]

函数没有返回,属于 UB,经典案列 NOIP T2 T3 开 O2 爆零。

  1. unused variable 'X' [-Wunused-variable]

没用到某变量,可以忽略。

  1. control reaches end of non-void function [-Wreturn-type]

函数结尾处没有返回,UB不清楚,但基本会WA。

关于结尾处定义:

int phigy
{
    if(x==0)return 0;
    if(x!=0)return 0;
}

这会有警告。

int phigy
{
    if(x==0)return 0;
    else return 0;
}

这不会有警告。

4.suggest parentheses around assignment used as truth value [-Wparentheses]

if(res=dfs(x,flew)>0)
{

}

此情况警告,意思是要明确是 = 不是 == 。

if((res=dfs(x,flew))>0)
{

}

这样解决。

  1. [Warning] suggest parentheses around '+' inside '>>' [-Wparentheses]

输入输出时的运算可能与左移右移产生歧义