c++ - 如何在 CodeBlocks 中启用缩小警告?

标签 c++ codeblocks compiler-warnings type-narrowing

我正在使用 codeblocks IDE 编写 C++ 程序

int main()
{
int i =0;
int f = 3.14;
i = f; //must give me a warning message, possible loss data.
}

为什么编译不显示缩小警告消息? 如何启用它?

注意:我已将编译器选项修复为 -std=c++11 -Wall

最佳答案

其他编译器选项中放置-Wconversion

(代码:: block 16)

enter image description here

对于:

int i =0;
int f = 3.14;
i = f;

warning: conversion to ‘int’ alters ‘double’ constant value [-Wfloat-conversion]


我经常使用的一些有用的警告:

enter image description here

-Wall -Weffc++ -Wextra -pedantic -Wfatal-errors -pedantic-errors

关于c++ - 如何在 CodeBlocks 中启用缩小警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43447796/

相关文章:

c++ - 如何在 C++ 中正确打印 double 到 cout

c++ - 如何使用代码块和 gcc 创建预编译头文件

c++11 线程、SFML 和 code::blocks

c++ - 更强大的 AC_COMPILE_IFELSE 功能测试?

c++ - Visual Studio 2015 - 编译器警告(2 级)C4146

c++ - 声明第一个单精度冲突的数字是 131072.02 是否正确? (正数,考虑 2 位数字作为尾数)

c++ - 释放内存失败 : free(): invalid next size (fast):

c++ - 在同一文件中使用#pragma once 和#ifndef include guard

Code::Blocks :带有指针 FILE 参数的函数(和函数原型(prototype))出现错误

c# - 突出显示代码中的动态调用