[b][red]This message was edited by Yuvaraja at 2004-9-20 0:59:1[/red][/b][hr]
In C, using format string specified we can easily print the ASCII values of character, thats its value. But in C++, we need to typecast it for having its value.
If we decided to do so, we need to cast it only to 'int' or to 'unsigned int'. Why I ask this question is that I faced while studying C++ templates :
I had written an template, which will print the no.of bits, Max and Min range of given data type.
void TypeSize ( TYPE tyTempVar, char *pcTypeName )
unsigned char ui8NoOfBits;
TYPE MyTest = 0;
ui8NoOfBits = 1;
/* Find no. of bits in given data type */
ui8NoOfBits = GetNoOfBits ( MyTest );
/* Check the sign type and find its max, min */
if ( ( ( TYPE ) ( 0x1L << ( ui8NoOfBits - 1 ) ) ) > 0 )
/* It is Unsigned */
ukMinValue = 0;
ukMaxValue = ( TYPE ) ukMinValue - 1;
bSingStatus = 0;
/* It is Signed */
ukMinValue = ( TYPE ) ( 0x1L << ( ui8NoOfBits - 1 ) );
ukMaxValue = ukMinValue - 1;
bSingStatus = 1;
/* Print the found values */
if ( bSingStatus )
cout << pcTypeName << unsigned int ( ui8NoOfBits ) << ' ' << signed int ( ukMinValue ) << ' ' << signed int ( ukMaxValue ) << endl;
cout << pcTypeName << unsigned int ( ui8NoOfBits ) << ' ' << unsigned int ( ukMinValue ) ' ' << unsigned int ( ukMaxValue ) << endl;
In this, i had typecasted to signed or unsigned int for printing the ranges. Do u have any other way to do this?
Thank you very much for your reply in advance...
Again I faced another problem, while trying to print the max range of a bit field :
unsigned char a : 1 | 0;
char b : 1 | 7;
In the above, I want to know the max and min range of bit field 'b'.