473,395 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

drowning in warnings

I finally get my 6.0 c++ code to compile in .NET. Now there are a lot
of warnings in the .NET compile. Under 6.0, the complile of a very
large body of code results in 25 warnings. With C++ .NET, the same
file compiles with 228 errors.

Here is an example:

int SecondsToMilliSeconds( double nSeconds )
{
return( nSeconds * 1000 ) ;
}

gives warning:
c:\srcom\acsubs.cpp(2584) : warning C4244: 'return' : conversion from
'double' to 'int', possible loss of data.

Under 6.0 I dont see that warning.

I am worried that all the warnings will obscure the warnings that I
need to see.

Can I tell the .NET compile to compile under the warning rules of 6.0?

-Steve
Nov 16 '05 #1
5 1106
"Steve Richter" <co********@yahoo.com> wrote in message
news:c0**************************@posting.google.c om...
I finally get my 6.0 c++ code to compile in .NET. Now there are a lot
of warnings in the .NET compile. Under 6.0, the complile of a very
large body of code results in 25 warnings. With C++ .NET, the same
file compiles with 228 errors.

Here is an example:

int SecondsToMilliSeconds( double nSeconds )
{
return( nSeconds * 1000 ) ;
}


I just copied that function into a source file and compiled it with 6.0. I
see the same warning. Are you sure that the 6.0 project was set to compile
at the same warning level and/or that someone did not explicitly disable
some warnings there?

Why not inhibit the warnings you deem innocuous by means of a cast or
pragma?

Regards,
Will

Nov 16 '05 #2
"William DePalo [MVP VC++ ]" <wi***********@mvps.org> wrote in message news:<#r**************@TK2MSFTNGP09.phx.gbl>...
"Steve Richter" <co********@yahoo.com> wrote in message
news:c0**************************@posting.google.c om...
I finally get my 6.0 c++ code to compile in .NET. Now there are a lot
of warnings in the .NET compile. Under 6.0, the complile of a very
large body of code results in 25 warnings. With C++ .NET, the same
file compiles with 228 errors.

Here is an example:

int SecondsToMilliSeconds( double nSeconds )
{
return( nSeconds * 1000 ) ;
}
I just copied that function into a source file and compiled it with 6.0. I
see the same warning. Are you sure that the 6.0 project was set to compile
at the same warning level and/or that someone did not explicitly disable
some warnings there?


nothing that I am aware of. but there is a lot in all of this I am
not aware of.
Why not inhibit the warnings you deem innocuous by means of a cast or
pragma?


I am afraid of casting. Kind of like how Kramer in Seinfeld is afraid
of clowns. ( I work half my time on an IBM as400. The system is very
nice, but if you break the rules, they break your bones! )

In this case, is that the official way to tell the compiler that I am
aware that I might lose some data in the assignment?
return (int) ( nSeconds * 1000 ) ;

I'd prefer some sort of built in operator:
int nValue = _DoubleToInt( nSeconds * 1000 ) ;
Another warning I get a lot is from the following:
int CalcSomething( int Input )
{
switch( Input )
{
case 1:
return 25 ;
default:
LogAndThrowTextException( L"Input to CalcSomething is no good"
) ;
return 0 ; // never runs. but get warning if not present.
}
}

The compiler does not know that the "LogAndThrowTextException"
function throws an exception. If I dont add the "return" stmt after
the "LogAndThrow...", then I get an all code paths dont return a
value. But I dont like inserting the "return 0" because I think it
adds to code clutter.

It would be better for me if I there was a non standard way to tell
the compiler that "LogAndThrowTextException" always throws an
exception and is in affect a "returning code path".

thanks,

-Steve
Nov 16 '05 #3
Hi,

switch (Input)
{
case 1:
return 25;
default:
LogAndThrowTextException(...);
__assume(0); // works on VC6 too
}

Cheers,
Stoyan

"Steve Richter" <co********@yahoo.com> wrote in message
news:c0**************************@posting.google.c om...
"William DePalo [MVP VC++ ]" <wi***********@mvps.org> wrote in message

news:<#r**************@TK2MSFTNGP09.phx.gbl>...
"Steve Richter" <co********@yahoo.com> wrote in message
news:c0**************************@posting.google.c om...
I finally get my 6.0 c++ code to compile in .NET. Now there are a lot
of warnings in the .NET compile. Under 6.0, the complile of a very
large body of code results in 25 warnings. With C++ .NET, the same
file compiles with 228 errors.

Here is an example:

int SecondsToMilliSeconds( double nSeconds )
{
return( nSeconds * 1000 ) ;
}


I just copied that function into a source file and compiled it with 6.0. I see the same warning. Are you sure that the 6.0 project was set to compile at the same warning level and/or that someone did not explicitly disable
some warnings there?


nothing that I am aware of. but there is a lot in all of this I am
not aware of.
Why not inhibit the warnings you deem innocuous by means of a cast or
pragma?


I am afraid of casting. Kind of like how Kramer in Seinfeld is afraid
of clowns. ( I work half my time on an IBM as400. The system is very
nice, but if you break the rules, they break your bones! )

In this case, is that the official way to tell the compiler that I am
aware that I might lose some data in the assignment?
return (int) ( nSeconds * 1000 ) ;

I'd prefer some sort of built in operator:
int nValue = _DoubleToInt( nSeconds * 1000 ) ;
Another warning I get a lot is from the following:
int CalcSomething( int Input )
{
switch( Input )
{
case 1:
return 25 ;
default:
LogAndThrowTextException( L"Input to CalcSomething is no good"
) ;
return 0 ; // never runs. but get warning if not present.
}
}

The compiler does not know that the "LogAndThrowTextException"
function throws an exception. If I dont add the "return" stmt after
the "LogAndThrow...", then I get an all code paths dont return a
value. But I dont like inserting the "return 0" because I think it
adds to code clutter.

It would be better for me if I there was a non standard way to tell
the compiler that "LogAndThrowTextException" always throws an
exception and is in affect a "returning code path".

thanks,

-Steve

Nov 16 '05 #4
Steve Richter wrote:
"William DePalo [MVP VC++ ]" <wi***********@mvps.org> wrote in
message news:<#r**************@TK2MSFTNGP09.phx.gbl>...
Why not inhibit the warnings you deem innocuous by means of a cast or
pragma?

I am afraid of casting. Kind of like how Kramer in Seinfeld is afraid
of clowns. ( I work half my time on an IBM as400. The system is very
nice, but if you break the rules, they break your bones! )

In this case, is that the official way to tell the compiler that I am
aware that I might lose some data in the assignment?
return (int) ( nSeconds * 1000 ) ;


Yes it is.

I'd prefer some sort of built in operator:
int nValue = _DoubleToInt( nSeconds * 1000 ) ;
Perhaps you'd prefer static_cast<int>( nSeconds * 1000 );


Another warning I get a lot is from the following:
int CalcSomething( int Input )
{
switch( Input )
{
case 1:
return 25 ;
default:
LogAndThrowTextException( L"Input to CalcSomething is no good"
) ;
return 0 ; // never runs. but get warning if not present.
}
}

The compiler does not know that the "LogAndThrowTextException"
function throws an exception. If I dont add the "return" stmt after
the "LogAndThrow...", then I get an all code paths dont return a
value. But I dont like inserting the "return 0" because I think it
adds to code clutter.
Add __declspec(noreturn) to the declaration of LogAndThrowException and the
warning will be suppressed.

It would be better for me if I there was a non standard way to tell
the compiler that "LogAndThrowTextException" always throws an
exception and is in affect a "returning code path".


There is a way - see above.

-cd
Nov 16 '05 #5
"Steve Richter" <co********@yahoo.com> wrote in message
news:c0**************************@posting.google.c om...
gives warning:
c:\srcom\acsubs.cpp(2584) : warning C4244: 'return' : conversion from
'double' to 'int', possible loss of data.

Under 6.0 I dont see that warning.

I am worried that all the warnings will obscure the warnings that I
need to see.


But you do need to see this warning, it's not good code.
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Kylotan | last post by:
I have the following code: def IntToRandFloat(x): """Given a 32-bit integer, return a float in """ x = int(x) x = int(x << 13) ^ x return...
12
by: Gary | last post by:
Hi! guys, I have a SQL agent job fails because it gets 10 warnings when it runs a stored procedure. These warnings are trivial and can be ignored. Can I make it ignore these warnings and...
3
by: Terry Richards | last post by:
mysql 4.1.9-standard how do i find exactly what the warnings are when i only get Query OK, 1 row affected, 1 warning (0.00 sec) :-)^2
30
by: prasanna | last post by:
i will be very thankful if you sent all the errors and warnings regarding to the language C thank you
22
by: John Fisher | last post by:
void f(int p) { } Many (most?) compilers will report that p is unreferenced here. This may not be a problem as f may have to match some common prototype. Typically pointers to functions are...
6
by: pete142 | last post by:
When I compile this code: typedef unsigned char BYTE; BYTE * IpString(unsigned int ip) { static BYTE ipString; ipString = (BYTE) 0xff & (ip >24); ipString = (BYTE) 0xff & (ip >16);
3
by: gil | last post by:
Hi, I'm trying to find the best way to work with compiler warnings. I'd like to remove *all* warnings from the code, and playing around with the warning level, I've noticed that compiling with...
1
by: billiejoex | last post by:
Hi there, into a module of mine I 'warn' a message if a certain situation occurs: def add_anonymous_user(permissions=('r'): if 'w' in p: import warnings warnings.warn("it's not rencommended...
1
by: Robert Singer | last post by:
Platform: winXP, excel 2003 Python 2.5.2 XLWriter 0.4a3 (http://sourceforge.net/projects/pyxlwriter/) Is anyone here using this very nice package, for writing excel files? I'm using it on...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.