[BUG;FIX]

Mats Nygren nygren at sics.se
Tue Dec 21 15:16:09 UTC 1999



On Tue, 21 Dec 1999, Stephan Rudlof wrote:

> "Andrew C. Greenberg" wrote:
> > 
> > Its a bug in all versions of the CCodeGenerator, which fails to
> > generate correct code for complex loops of the form:
> > 
> >         [exp1. condition] whileTrue: [exp2. exp3].
> > 
> > With the attached changeset, the CCodeGenerator now generates for this case:
> > 
> >         exp1.
> >         while(condition) {
> >                 exp2;
> >                 exp3;
> >                 exp1;
> >         }
> > 
> > I haven't had a chance to fully test the patch, but I'm hoping
> > Stephen or Andreas will be able to put it through its paces.
> 
> It works, thank you.
> 
> > I'd
> > like to do a more elegant revision of the code generator for loops
> > when I find some time, but for now this patch should serve.  (Or
> > perhaps we should build less complex loops?)
> 
> I don't know how to write this construct more elegantly in C; 'do {}
> while()' doesn't help.

I dont claim this to be more elegent, however, here are two alternatives
that doesnt repeat exp1:

   while (1) {
      exp1;
      if (!(condition)) break;
      exp2;
      exp3;
   }

   while ((exp1), condition) {
      exp2;
      exp3;
   }
   // this assumes exp1 to be an expression (without if, switch, while
   // etc)

Since this is my first posting in this mailinglist I take the opportunity
to say that I appreciate your work a lot. When I am more acquainted with
it I hope to contribute. All the best and a happy new millennium.

/Mats Nygren





More information about the Squeak-dev mailing list