[vox-tech] loop never exits!
Brian Lavender
brian at brie.com
Thu Apr 22 19:51:40 PDT 2010
On Wed, Apr 21, 2010 at 11:43:49PM +0700, Robert Parker wrote:
> On Wed, Apr 21, 2010 at 11:37 PM, Brian Lavender <brian at brie.com> wrote:
> > I told the compiler to go through a loop while a certain expression
> > evaluates to true. When the expression evalates to false, the loop
> > should terminate. If I had provided no expression, or I had provided
> > true, or some value that would always evaluate to true, then I would
> > expect the compiler to do as I tell it.
> >
> > I have provided an expression for the loop to terminate that could
> > evaluate to false, yet will never evaluate to false.
> >
> > This determination can be done through static analysis. Hence,
> > I am still convinced that the compiler should issue a warning. Yet,
> > I am still looking for a contradiction to my theory.
>
> If you are using an open source compiler just download the source and
> rewrite it so that it does what you want instead of just continuing to
> complain about it.
You know, I usually do preliminary research before I start a project.
Assuming that I wanted to implement this fix, I would at least research
a bit. I have never dug into gcc, but someday I will or at least I will
do some work with bison, antlr, or other language development, so don't
underestimate me!
Someone else was thinking along the same line as me and thinks
this is fair warning. I just needed to turn on extra warning flags! In
either case, using "i > -1" or "i >= 0" is detectable by gcc.
brian at davostro:~/school/Project/practice$ make test_loop
cc -Wextra -Wall -Wtype-limits test_loop.c -o test_loop
test_loop.c: In function 'main':
test_loop.c:8: warning: comparison between signed and unsigned integer expressions
brian at davostro:~/school/Project/practice$ make test_loop
cc -Wextra -Wall -Wtype-limits test_loop.c -o test_loop
test_loop.c: In function 'main':
test_loop.c:8: warning: comparison of unsigned expression >= 0 is always true
--
Brian Lavender
http://www.brie.com/brian/
"There are two ways of constructing a software design. One way is to
make it so simple that there are obviously no deficiencies. And the other
way is to make it so complicated that there are no obvious deficiencies."
Professor C. A. R. Hoare
The 1980 Turing award lecture
More information about the vox-tech
mailing list