[Vala] [vala] for loop



Hello!

I am using vala for some months now and first I want to say: great job! I like this language!
But today I looked at some generated C-Code an when you have a simple for-loop in vala:

int main()
{
  int i;
  for (i = 0; i < 10; i++)
  {
    stdout.printf("test %d\n", i);
  }
  return 0;
}

then you get the following C-Code:

        gint i = 0;
        {
                gboolean _tmp0_;
                i = 0;
                _tmp0_ = TRUE;
                while (TRUE) {
                        if (!_tmp0_) {
                                i++;
                        }
                        _tmp0_ = FALSE;
                        if (!(i < 10)) {
                                break;
                        }
                        fprintf (stdout, "test %d\n", i);
                }
        }

Why do you write a for loop in this way? I think there are some reasons, but I did not find them.
But when it is necessary to write a while loop instead a for loop would it not be better, if the generated 
code looks like this?

gint i = 0;
/* The first check */
while (i < 10)
{
  /* The loop body */
  fprintf (stdout, "test %d\n", i);

  i++;
}

In this way you do not need the _tmp0_ variable, which could improve the performance of the for loop, 
couldn't it?

Gerhard


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]