Quote:Original post by Colin Jeanne
memset() will set one byte at a time. If yor datatype is more than a byte long then you can use sizeof().int sum_ints[25];/* Set every byte in this array of ints to 0 */memset(sum_ints, 0, 25 * sizeof(int));
In fact, memset (and memcpy BTW) will set n bytes at a time (where n is 4 on 32 bit machine). memset is a rather clever routine that will write memory as fast as it can (you won't be able to beat it; Adam Hamilton's version is the core of memset, but memset first align variable and try to pair asm instructions in order to achieve the best speed). Only the lowest byte of the memset argument is used (the other bytes are discarded).
You can use std::fill or std::fill_n to copy more than one byte to a destination variable.
(edit:)
Quote:Original post by AP
Really, memset() and calloc() aren't very useful in a strictly conforming program where you can't assume "all bits 0" is a valid representation of floating point 0 and/or a null pointer. For similar reasons, the most common value passed as the second parameter to memset() is 0.
AFAIK, floating point 0 is 0 (IEEE standard), and NULL pointer is 0 too (of course, if you don't like your co-workers, you can define NULL to be 42; the NULL value is implementation defined, but is supposed to be the null pointer constant (which is defined as an integral constant expression rvalue of integer type that evaluates to zero (4.10 of the holy C++ standard))). Did I miss something?
HTH,