From: David F. on 5 Mar 2010 07:24 A 1993 Borland compiler finds this problem (i>=0 always true) but VS2008 doesn't? for (unsigned i = strlen("test") - 1; i>=0; i--) { .. do stuff.. }
From: David Lowndes on 5 Mar 2010 14:18 >A 1993 Borland compiler finds this problem (i>=0 always true) but VS2008 >doesn't? > >for (unsigned i = strlen("test") - 1; i>=0; i--) { > .. do stuff.. >} I thought older versions of the MS compiler used to catch that one so I'm disappointed to note that it doesn't catch it now. It now only shows up with the static analyser :( warning C6295: Ill-defined for-loop: 'unsigned int' values are always of range '0' to '4294967295'. Loop executes infinitely Dave
From: Anonymous on 6 Mar 2010 08:44 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. -- 40th Floor - Software @ http://40th.com/ PhantasmX3 - The finest sound in the world CastleKeeper - IP camera surveillance/recorder, NVR
From: David Lowndes on 6 Mar 2010 09:32 >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. I think the point is that you can do the former unintentionally - it was deemed worthwhile having as a warning in older products, so why not now? I am surprised that it wasn't a warning, I'm pretty sure it used to be caught. The static analyser option isn't available in some editions of the tools. Dave
From: Alexander Grigoriev on 6 Mar 2010 11:36
Such warning (condition always true) was enabled in some version of DDK. Unfortunately, it was creating too much noise from some macros. The warning needed to be smarter, to distinct a constant expression from a non-constant expression which is always true (or false). "David Lowndes" <DavidL(a)example.invalid> wrote in message news:omp4p5pgev17qe20no62euremfs8g03o2r(a)4ax.com... > >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. > > I think the point is that you can do the former unintentionally - it > was deemed worthwhile having as a warning in older products, so why > not now? I am surprised that it wasn't a warning, I'm pretty sure it > used to be caught. > > The static analyser option isn't available in some editions of the > tools. > > Dave |