Home > OS >  Why does the memccpy function use an int parameter?
Why does the memccpy function use an int parameter?

Time:11-16

memccpy is defined as:

void *memccpy(void *dest, const void *src, int c, size_t n)

I understand that integer c is used as an unsigned char by type casting.

Then I think

void *memccpy(void *dest, const void *src, unsigned char c, size_t n)

looks better. Is there any reason memccpy must use an int parameter?

CodePudding user response:

In ancient C, there was no way to pass an argument as an unsigned char; all arguments were promoted to at least int. Changing the parameter type to unsigned char now would break compatibility. (That could possibly be worked around, but there is no demand for it.)

  •  Tags:  
  • c
  • Related