From: David F. on

<hel(a)40th.com> wrote in message
news:esflpMTvKHA.5940(a)TK2MSFTNGP02.phx.gbl...
> DF [Fri, 5 Mar 2010 04:24:17 -0800]:
> >A 1993 Borland compiler finds this problem (i>=0 always true) but VS2008
> >for (unsigned i = strlen("test") - 1; i>=0; i--) {
>
>
> So where's the error? It's not illegal to shoot
> yourself in the foot. How is that any different
> than for (;;) {...}? DL said analyze found it.
> Good enough to stop from pulling the trigger.
>

Because that's what a good compiler is supposed to do, help prevent
problems. Why have any warning or error checking at all, just compile it
and making assumptions on errors and no warning notifications and let the
programmer step through the 100's of thousands of lines of code trying to
find the small mistake.

In this case it was converting a class where a programmer used an int
instead of unsigned and int was causing a problem do to check that only
checked < some limit and the input could be negative causing a crash. but
due to the lack of VS ability to report problems, we had to solve it a
different way.

From: Anonymous on
DF [Sat, 6 Mar 2010 09:13:50 -0800]:
>Because that's what a good compiler is supposed to do, help prevent
>problems. Why have any warning or error checking at all, just compile it

for (unsigned i = strlen("test") - 1; i>=0; i--) {
rc = 0;
}

...cpp(3005) : warning C6295: Ill-defined for-loop: 'unsigned int'
values are always of range '0' to '4294967295'. Loop executes infinitely

Just sayin' (use a tool that does what you want). Is
this in vs10 64-bit now?

--
40th Floor - Software @ http://40th.com/
PhantasmX3 - The finest sound in the world
CastleKeeper - IP camera surveillance/recorder, NVR
From: "Jialiang Ge [MSFT]" on
Hi David

In Visual Studio 2008, if you enable /analyze switch
(http://msdn.microsoft.com/en-us/library/ms173498.aspx), the compiler will
produce the warning:

warning C6295: Ill-defined for-loop: 'unsigned int' values are always of
range '0' to '4294967295'. Loop executes infinitely

Is this what you are looking for?

Regards,
Jialiang Ge
Microsoft Online Community Support

=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================