sketch resets millis()

The following code resets millis() on a pro mini and I have no idea why.

unsigned long something[10]; //  something array 
int printDelay = 1000;
int count = 0;

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);

}

// the loop routine runs over and over again forever:
void loop() {

  Serial.println(millis());
  count++;
  delay(printDelay);        // delay 

    if (count == 5){
    clearSomething();
  }
}

void clearSomething() {
  count = 0;
  for (int thisThing = 0; thisThing < sizeof(something); thisThing++) {
    something[thisThing] = 0;
  }
  Serial.println("Cleared.");
}

Looping through the array is where it seems to get reset.

Any ideas why?

sizeof(something) is 40, that could be a problem.

The usual idiom that you probably want is sizeof(something)/sizeof(something[0])

It’s resetting millis(), but not just millis(). It’s clobbering something in RAM, and resetting the Arduino.

Jack Christensen is right, sizeeof(something) is 40.
Have a look at this…

unsigned long something[10]; //  something array 
int printDelay = 1000;
int count = 0;

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(115200);
  Serial.println("");
  Serial.println("In setup()");
}

// the loop routine runs over and over again forever:
void loop() {

  Serial.println(millis());
  count++;
  delay(printDelay);        // delay 
  Serial.print("count = ");
  Serial.println(count);
  if (count == 5){
    clearSomething();
  }
}

void clearSomething() {
  for (byte thisThing = 0; thisThing < 10; thisThing++) {
    Serial.print("thisThing = ");
    Serial.println(thisThing);
    something[thisThing] = 0;
  }
  Serial.println("Cleared.");
}

If that for iterates to sizeof(something), it exceeds the bounds of the array. Try changing it to that, and you’ll see that thisThing counts to 8, then you end up back in setup().

Why 8? Because there is no delay in the clearSomething() function, and thisThing is well past the end of the array before another Serial.print() has a chance to show up on your serial monitor.

Thanks guys. I have seen people looking for ways to reset the arduino through code and I may have found one inadvertently.