Search code examples
carraysmemset

I'm having an `argument of type` warning while using memset


I have the array;

volatile uint32_t SoftTimers[8] ;

I want to reset my arrays all content to zero in the program(not initialization). I searched for this and found memset. But im having this warning(not error) while using this function, is that a problem?

I used memset like this:

memset(SoftTimers, 0, sizeof(SoftTimers));

And this is the warning message:

warning: #167-D: argument of type "volatile uint32_t *" is incompatible with parameter of type "void *"


Solution

  • You cannot use memset in this case, because it takes a non-volatile pointer, while you are trying to pass a volatile pointer:

    6.7.3 Type qualifiers

    1. If an attempt is made to refer to an object defined with a volatile-qualified type through use of an lvalue with non-volatile-qualified type, the behavior is undefined.

    Write your own function, that takes a pointer to volatile uint32_t type.