* Jack Klein:
Under no preconditions at all.
From paragraph 3 of 3.9.1 Fundamental types:
"The range of nonnegative values of a signed integer type is a
subrange of the corresponding unsigned integer type, and the value
representation of each corresponding signed/unsigned type shall be the
same."
It is worth noting that the standard defines the term "value
representation" in a para preceding this one.
It doesn't mean the representation of a value in terms of 0's and 1's...
This is a case where possibly the intent of the standard is different
from the actual wording, but anyway, it's not a good idea to use memset
for anything if it can be avoided, since it's dangerous in many ways:
the possibility of 0 not being represented by all bits 0 for some types,
the ease with which incorrect limits can be specified, the possibility
of being applied to what is actually non-contigous storage.
I'd advice the OP to use std::vector instead of raw arrays.
Safely & efficiently clearing a std::vector v is very very easy:
zeroAllElementsIn( v );
where zeroAllElementsIn can be defined as
template< typename T >
void zeroAllElementsIn( std::vector<T>& v )
{
std::size_t const size = v.size();
v.clear();
v.resize( size );
}
or
template< typename T >
void zeroAllElementsIn( std::vector<T>& v )
{
std::fill( v.begin(), v.end(), T() );
}
or whatever, just not memset.