Comments

: The prototype for the function goes like this and it fills the first : n bytes of the memory area pointed to be s with the constant byte c.: : void *memset(void *s, int c, size_t n);: : If you look at the implementation of the function, the second : parameter is converted to

: In C and C++ char parameters are always promoted to integers to : speed up accessing them. Yes, they could have declared it as char : but it would cause a few more assembly instructions, and when memset : was first introduced into the language over 20 years ago computers : were much much slower then they are today, so every nanosecond was : important.

Still, this is a very dumb function prototype. If the CPU is using a certain bus size, it is up to the compiler to optimize the parameters and put them in blocks of 16 or 32 bits. Because... what happens if I decide to write code for the most common computer used in the world, an 8-bit microcontroller? The program gets slower because I must pass an additional junk byte to the stack.

So in my opinion, the answer to the question why they used an int for memset is: because they weren't thinking in a rational and system-independant way when they wrote the C standard. This particular function is no doubt written to suit ancient 16-bit Solaris computers.

: : So in my opinion, the answer to the question why they used an int : for memset is: because they weren't thinking in a rational and : system-independant way when they wrote the C standard. This : particular function is no doubt written to suit ancient 16-bit : Solaris computers.

Its up to the compiler to determine the size of any object other than char. So a compiler targeting an 8-bit processor could easily make sizeof(int) = 1 instead of 2, 4 or something larger. If that is the case (I don't know whether it is nor not) then you don't have an argument.

The C language was originally written by K&R to write the Unix operating system, but I don't know what kind of computer they used. If the memset function was going to present a problem on other platforms then it would have shown up sometime in the past 30 years or so and would probably have been changed by now. I'm not about to out-guess all those Ph.D's so I'd say memset() is pretty darned stable and working correctly as intended.=============================================never lie -- the government doesn't like the competition. (Author unknown)

: Its up to the compiler to determine the size of any object other : than char. So a compiler targeting an 8-bit processor could easily : make sizeof(int) = 1 instead of 2, 4 or something larger. If that : is the case (I don't know whether it is nor not) then you don't have : an argument.

"Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign."

And then they say that the minimum and maxiumum values of and int should be -32767 and 32767. So ANSI C does not allow 8-bit int. The above was however taken from C99, but I'm pretty sure C89 says the very same.