Hi everyone! Can anyone tell me how the compiler cast an int to a char? I need this information for a assembly work.
Thanks any help!
Printable View
Hi everyone! Can anyone tell me how the compiler cast an int to a char? I need this information for a assembly work.
Thanks any help!
If I understand your question correctly...
a char is just an 8-bit integer, because a char is just one of the 255 ASCII codes.
Same as the short datatype.
Code:int x = 5;
char c = (char)x; //Here, x gets explicitly demoted to a char
char d = x; //Here, x gets implicitly demoted to a char
Quote:
Originally Posted by gustavosserra
Well, if you were working with a big-endian machine, just generate the appropriate 'mov byte' opcode, for little-endian, index the 4th byte of the integer (use that offset) in the opcode.
>> Same as the short datatype.
These days, shorts are typically 16 bits.
C++ cast:
Code:int Alpha = 35;
char Beta = static_cast<char>(Alpha);
>> Can anyone tell me how the compiler cast an int to a char?
As Sebastiani posted, you'll want to write assembly that accomplishes the following:
ggCode:unsigned int I = 0xabcdef12;
unsigned short S = I;
unsigned char C = I;
cout << hex;
cout << "I = 0x" << I << endl;
cout << "S = 0x" << S << endl;
cout << "C = 0x" << (int)C << endl;
Assembly. Right! If you use VC++, write a program that does a c ast then add the /FA flag in the compilation options. This will produce a formatted assembly output file every time you compile. Then all you have to do is sniff out the part that does the casting.
Thanks everyone! Unfortunately I did not explain my problem well. I know how to tell the compiler to cast, but do not know how it implements. Thanks anyway =)
Sebastiani: thanks man! Iĺl do this way!
I didn't see the later posts! Thanks Codeplug and Magos!!!