The value argument to memset()
is only a single byte, even though the type for the argument is int
.
The manual page describes the function as:
memset - fill memory with a constant byte
So, no more than the least-significant 8 bits of d_val
will be written to memory. Since you're treating the memory as an array of short
, you get "mangled" values that consist of the same byte repeated through the bytes of the short
.
In ... short, don't do this; use a for
loop to do a repeated write of actual short
s.