error: 'for' loop initial declaration

I got a question.
I try to use a .c-library which is written for an Atmel AVR microcontroller.

http://benryves.com/projects/tvtext

If I try to compile I get this message:
'for' loop initial decleration used outside C99

This is the code part of the error-causing:

for (uint8_t r = tvtext_viewport_top; r <= tvtext_viewport_bottom; ++r, p += TVTEXT_BUFFER_WIDTH) {
            memmove(p, p + 1, tvtext_viewport_right - tvtext_viewport_left);
            p[tvtext_viewport_right - tvtext_viewport_left] = tvtext_cleared;
      }

I think I know why: The for-loop has to many arguments for the C99 mode.

My questions:

  1. Depents "p += TVTEXT_BUFFER_WIDTH" which the "++r"?
  2. How often is "p += TVTEXT_BUFFER_WIDTH" called. Each run/loop?
  3. Which mode accepts 4 arguments in a loop declaration?

Thanx

The problem is 'classic' C doesn't allow for loops of the form

for (int i = 0;

but C++ does.
Try putting:

uint8_t r;
for (r = tvtext_viewport_top; r <= tvtext_viewport_bottom; ++r, p += TVTEXT_BUFFER_WIDTH)
  1. Depents "p += TVTEXT_BUFFER_WIDTH" which the "++r"?
  2. How often is "p += TVTEXT_BUFFER_WIDTH" called. Each run/loop?
  3. Which mode accepts 4 arguments in a loop declaration?

Don't understand 1)
2) the "p+=" is called at the end of every pass through the loop, just before the loop condition is tested..
2) There is nothing wrong with four "arguments".

Thanx, your are right! :slight_smile:

I was irritated cause I found in the arduino reference only "for loop" examples with 3 arguments.

Even C would allow you to write:

for (i = 0, j = 0; i < 12; i++, j++)

About the only thing you can't have is multiple conditions.