Is there a gcc 4.2 warning like Visual Studio regarding possible data loss?

Is there a gcc flag so that long to short conversions generate a warning about possible data loss?

I am working on a C ++ application that compiled for both Visual Studio (2005) and GCC 4.2 (for Mac OS X).

The warnings that Visual Studio emits follow this pattern:

: warning C4244: 'argument' : conversion from 'long' to 'short', possible loss of data

I tried Conversion, but that is not quite what I am looking for. The only thing I managed to find was an experimental flag - Wcoercion, associated with GCC 4.3 (which I'm not sure if we want to invest in it yet).

April 22, 2009 @ 11:00 AM EST Edit: To clarify, I want to see this warning. We have code where we want to know when data loss will occur. If I have a code:

unsigned long value1 = LONG_MAX;
std::cout << "value1: " << value1 << std::endl;

unsigned short value2 = value1;
std::cout << "value2: " << value2 << std::endl;

:

  value1: 2147483647
  2: 65535

, , . Visual Studio.

gcc 4.2?

+5
3

GCC 4.2, ​​ GCC 4.3. Wiki, .

schnaader Evan Teran , .

+4

GCC, , , .

+4

Use -Wconversion. It seems to you that this is necessary, even if you have already specified -Wall.

It definitely works in gcc4.3. If it has not been fixed by version 4.2, you will need to update it to get it.

Warning example:

warning: conversion to 'short int' from 'int' may alter its value
+4
source

All Articles