drowning in warnings

  • Thread starter Thread starter Steve Richter
  • Start date Start date
S

Steve Richter

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
 
Steve Richter said:
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
 
William DePalo said:
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
 
Hi,

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

Cheers,
Stoyan

Steve Richter said:
"William DePalo [MVP VC++ ]" <[email protected]> wrote in message
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
 
Steve said:
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 said:
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
 
Steve Richter said:
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.
 
Back
Top