Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible loss of data warnings not being picked up!

Status
Not open for further replies.

hebak

Programmer
May 9, 2007
5
AU
Hi everyone

I am compiling code in MVC++ 7.1 with warning level 3.

The following code only produces a warning c4244 if placed in certain files in the solution.

int yyy=6;
double xxxx=6.0;
float ffff=6.0;
yyy=xxxx;

How is this happening when the warning level applies to all files in the project/solution?

Thanks for any help!
 
Why don't you use Warning Level 4? It shows a lot more problems.
 
Thanks for the suggestion.

I've already tried warning level 4.

It picks up a lot of other things (like variable declared but not used etc), but it still won't report the possible loss of data warning.

 
As far as I know C4244 warning fires only possible integral types data losses (short = int, for example), but double is not an integral type. IMHO int = double is not a subject of C4244 at all.
 
> The following code only produces a warning c4244 if placed in certain files in the solution.
Just so I understand you right.

The exact same code in two different files produces different error messages?


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Let me be a little more clear:

This is the setup I have:

I have a project with two different files A.cpp and B.cpp say. The issue I'm having is with code of this sort:

int yyy=6;
double xxxx=6.0;
yyy=xxxx;

When I put the code fragment into A.cpp and compile (or build the project) with warning level 3, I get:
"warning C4244: '=' : conversion from 'double' to 'int', possible loss of data"

However when I put the code fragment into B.cpp and compile (or build the project) with warning level 3, I get no warnings at all

What I don't understand is how I am getting warnings in one file but not the other (from the same peice of code, in the same project, being compiled with the same warning level)!

Thanks.
 
It probably has something to do with the other code in the files. Are there any other warnings or errors in either file? Can you remove most (all?) of the code in either file and still get the same results?
 
Do you get the same results with both Debug and Release builds? Maybe the part of code that has the bug isn't being called and is being optimized out or something?
 
Hey cpjust,

I get the same results with both debug and release builds. That part of the code is definately not being optimized out.

Thanks for the suggestion though.
 
Hey uolj,

There aren't any other warnings in the two files when I build with warning level 3.

If I build with warning level 4, I get all the annoying warnings like variable declared but not used...

I removed all the other code in the files, I still get the same results - a warning in one of the files, and no warnings in the other.

Thanks for your suggestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top