If you want to clear the whole thing, use memset:
memset(array1, 0, sizeof(array1));
For the AVR, this shouldn't save appreciable time. For larger
architectures, this can result in much faster execution, as this can be
extended out to 16, 32 and 64 bit fills rather than 8 bit fills. This
becomes more important if you are looking at making the code
semi-portable (yes, it is embedded, so portability is somewhat of a myth.)
John C
kernels_nz wrote:
Show quoted textHide quoted text
>
> Hi guys,
>
> I was writing some software for a scrolling message board when I came
> across the problem of clearing arrays during run-time in C.
>
> Usually I do something like:
>
> unsigned char array1[100];
> unsigned char count;
>
> for (count = 0; count < 100; count++){
>
> array1[count] = 0;
> }
>
> Has anybody ever come across a faster or more interesting way of
> accomplishing this ?
>
> Cheers
> Hein B
> Auckland, New Zealand
>
>