Clearing a global variable from within a function

Hi,

I have encountered an issue which perhaps shows my naivety with respect to variable scope in c++.

I declare a global variable

uint8_t _bits[5];  // buffer to receive data

This gets filled up during execution. However, I need to clear it between loops

if I use (from within void loop())

for (uint8_t i = 0; i < 5; i++) _bits[i] = 0;

it does not seem to set all of the elements to zero?

I am not sure what I am doing wrong, do I need to use pointers??

Thanks

Martyn

This is with code tags:

uint8_t _bits[5];  // buffer to receive data

for (uint8_t i = 0; i < 5; i++) 
  _bits[i] = 0;

Koepel:
This is with code tags:

uint8_t _bits[5];  // buffer to receive data

for (uint8_t i = 0; i < 5; i++)
  _bits[i] = 0;

Thanks, changed now

martynwheeler:
if I use (from within void loop())

for (uint8_t i = 0; i < 5; i++) _bits[i] = 0;

it does not seem to set all of the elements to zero?

That looks like it should work. The problem is probably somewhere else - which is why you should always post a complete program

Also, which elements are not set to zero, and how do you know?

…R

Robin2:
That looks like it should work. The problem is probably somewhere else - which is why you should always post a complete program

Also, which elements are not set to zero, and how do you know?

...R

Sorry, my debugging was doing something wrong! Sorry for bothering...