array subscript is above array bounds

The compiler is correct, as usual :slight_smile:

uint8_t databuff[128];

void loop()
{
}
void setup()
{
uint8_t index, ptr;
  //fill data buffer with numbers 0 to 127
  for (index = 0; index <= 127; index++);
  {
  ptr = index;
  databuff[ptr] = ptr;
  }
}

You have a semicolon after your for loop header, so the ptr = index code runs after the for loop has ended, and at this point, the value of index is 128 (i.e. the first value for which the for loop condition is false), hence it is out of bounds in the array.

You should always make your variables as local as possible, that would have avoided this issue:

  for (uint8_t index = 0; index <= 127; index++)
  {
    uint8_t ptr = index; // weird name for an index variable ...
    databuff[ptr] = ptr;
  }

Pieter