l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2010 Apr 22 20:47

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] loop never exits!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] loop never exits!

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@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@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@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

"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
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.