T
Tomás
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 UnsignedNumericType, std::size_t const i>
void SetAllElementsToZero( UnsignedNumericType (&array) )
{
memset( array, 0, i * sizeof(UnsignedNumericType) );
//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
types? The aim of the function is to take an array by reference and set
each element's value to zero.
#include <...
template<class UnsignedNumericType, std::size_t const i>
void SetAllElementsToZero( UnsignedNumericType (&array) )
{
memset( array, 0, i * sizeof(UnsignedNumericType) );
//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