When is it that memset caused problems?
I recall from posts in the past where someone
used memset in their code that invoked undefined
behavior.
What about the following?
char the_array[10];
memset(the_array, 'A', sizeof the_array);
does this invoked undefined behavior
or can create a trap representation?
iirc there were some issues involving
trap representations with memset usage.
Your particular example is just fine, and has well-defined results.
Unless you later pass the array to a function that accepts a string,
since it is not '\0' terminated. You are setting each character in
your array to 'A' which is guaranteed to be a valid value for a
character.
The issue is that when using calloc(), or memset(some_object, 0,
some_size), you set the memory to all bits 0. But all bits 0 is not
necessarily what you expect it to be.
The C standard guarantees that all bits 0 produces a valid value of 0
for all three of the character types. It also guarantees that it
produces a valid value of 0 in the all of the C99 optional exact width
integer types, if the compiler has such types. Technically it does
not guarantee that it produces valid values of 0 in the rest of the
"ordinary" integer types ((un)signed short, (un)signed int, (un)signed
long, (un)signed long long), but there is a defect report to correct
that in a future update.
What the C standard does not and never will guarantee is that all bits
0 produces the value 0.0, or any valid value, in floating point types.
It also does not guarantee that it produces the value NULL, or any
valid value, in pointer types.
There are definitely architectures where a null pointer does not have
the pattern of all bits 0. There are probably implementations where
all bits 0 is not the value of 0.0 in floating pointy types.