Search code examples
ctypesmemsetmanual

memset manual description: int type or constant byte?


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.


Solution

  • The standard has a better wording.

    Quoting C11, chapter 7.24.6.1,

    The memset function copies the value of c (converted to an unsigned char) into each of the first n characters of the object pointed to by s.