F
Frederick Gotham
On my system, the following doesn't work properly:
#define UCHAR_MAX ( ~( (unsigned char)0 ) )
Could someone please explain why it doesn't work? My hunch is that it has
something to do with integer promotion.
Since the previous example doesn't work, why is it that the following
does?
template<class AnyUnsignedIntegerType>
AnyUnsignedIntegerType MaxVal()
{
return ~AnyUnsignedIntegerType(0);
}
#include <iostream>
int main()
{
std::cout << (unsigned long) MaxVal<unsigned char>() << "\n\n";
/* Cast required so it prints as a number rather
than as a character */
}
#define UCHAR_MAX ( ~( (unsigned char)0 ) )
Could someone please explain why it doesn't work? My hunch is that it has
something to do with integer promotion.
Since the previous example doesn't work, why is it that the following
does?
template<class AnyUnsignedIntegerType>
AnyUnsignedIntegerType MaxVal()
{
return ~AnyUnsignedIntegerType(0);
}
#include <iostream>
int main()
{
std::cout << (unsigned long) MaxVal<unsigned char>() << "\n\n";
/* Cast required so it prints as a number rather
than as a character */
}