I have a question regarding memset
and its manual's entry. Here is what I can see in the manual for memset
:
void *memset(void *s, int c, size_t n);
[...]
DESCRIPTION
The memset() function fills the first n bytes of the memory area pointed to by s with the constant byte c.
[...]
The manual says with the constant byte c
, but c
is an integer, whose size actually depends on several factors (compiler, architecture ...).
In the general case, sizeof(int) > 1
(usually 4
).
My question is: Why isn't c
a char
, which always has a sizeof
of 1
and thus corresponds to a byte ?
And then, what is the 'real' behavior of memset in border cases (undefined?) ?
By border cases, i mean for instance a case where sizeof(int) = 4
, and n=7
.
The standard has a better wording.
Quoting C11
, chapter 7.24.6.1,
The
memset
function copies the value ofc
(converted to anunsigned char
) into each of the first n characters of the object pointed to bys
.