Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a gcc 4.2 warning similar to Visual Studio's regarding possible loss of data?
    text
    copied!<p>Is there a flag for gcc such that conversions from a long to a short will generate a warning about a possible loss of data?</p> <p>I'm working on a C++ application that is compiled for both Visual Studio (2005) and GCC 4.2 (for Mac OS X).</p> <p>The warnings that Visual Studio prints out follow this pattern:</p> <pre><code>: warning C4244: 'argument' : conversion from 'long' to 'short', possible loss of data </code></pre> <p>I've tried -Wconversion, but that isn't quite what I'm looking for. The only thing I've been able to find so far is an experimental flag, -Wcoercion, which is associated with GCC 4.3 (which I'm not sure if we want to invest in quite yet).</p> <p><strong>April 22, 2009 @ 11:00 EST Edit:</strong>To clarify, I want to see that warning. We have code where we want to know when a data loss would occur. If I have the code:</p> <pre><code>unsigned long value1 = LONG_MAX; std::cout &lt;&lt; "value1: " &lt;&lt; value1 &lt;&lt; std::endl; unsigned short value2 = value1; std::cout &lt;&lt; "value2: " &lt;&lt; value2 &lt;&lt; std::endl; </code></pre> <p>I get this expected result:</p> <p><strong> &nbsp;&nbsp;value1: 2147483647<br> &nbsp;&nbsp;value2: 65535 </strong></p> <p>In our code, we have special asserts put in place that perform the coercion and warn us if the executed-code would result in a loss of data. We found the places in our large code base using Visual Studio's warnings.</p> <p>Is there any way we can generate these warnings in gcc 4.2?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload