<pa**********@att.netwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
: This is copy-pasted from cplusplus.com:
:
: BEGINNING OF QUOTE
:
: void * memset ( void * buffer, int c, size_t num );
:
: Fill buffer with specified character.
: Sets the first num bytes pointed by buffer to the value specified by
: c parameter
:
: END OF QUOTE
:
: Since we are filling the buffer with a specified _character_, why is
: the 2nd parameter an int instead of a char?
What the function really does is store (unsigned char)c
at every memory address in [ buffer .. buffer+num )
: Yes, I know that chars are really ints but it still seems a confusing
: definition, and I'd greatly appreciate it if someone could explain why
: the authors of this function didn't choose type char for the 2nd
: parameter.
I think because in early C code char and int parameters were
automatically promoted to int (think of a time where you could
call a function without the compiler having seen its declaration).
: Also, could someone explain what happens when c == 0?
All memory bits in the addressed range will be set to zero.
Integer variables stored within the address range will
reliably be set to zero. On most platforms, pointers
and floating-point values will also be set to NULL / 0.0,
although this is not required to work (IIRC the Standard).
Any call to memset will result in undefined behavior if any
const or non-POD object is stored within the range (e.g. any
instance of a type that has a constructor, or stores a reference).
hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <
http://www.brainbench.com