Is the following fully legal and fully portable for all the unsigned
types? The aim of the function is to take an array by reference and set
each element's value to zero.
#include <...
template<class UnsignedNumeric Type, std::size_t const i>
void SetAllElementsT oZero( UnsignedNumeric Type (&array)[i] )
{
memset( array, 0, i * sizeof(Unsigned NumericType) );
//or:
memset( array, 0, sizeof (array) );
}
I writing a function at the moment that's manipulating an array which is
passed to it by reference. It needs to set a certain amount of the
elements to zero. It will only ever be given the unsigned types, e.g.:
unsigned
unsigned char
unsigned short
unsigned long...
Is the code fully portable and well defined? Is there a guarantee in the
Standard that the bit pattern in memory for all the aforementioned types
will be all zeros, ie. 0000 0000?
-Tomás
Comment