In the following dummy example, I get a warning and I don't understand how I can get rid of it without explicitly define a pointer with int *_str = (int*)str
:
#include <stdlib.h>
#include <stdint.h>
void foo(void *str, int c, size_t n) {
for (size_t i = 0; i < n; i++)
*((int*)str++) = c;
}
Here is what I get in gcc
:
gcc -c -std=c99 -Wpointer-arith test.c
test.c: In function ‘mymemset’:
test.c:7:20: warning: wrong type argument to increment [-Wpointer-arith]
*((int*)str++) = c;
^
What's wrong with my code?
NOTE
I know this question is quite similar to this one, but it doesn't explain why I cannot do it and why I get an error.