A
a
I am having trouble understanding the results of the following code:
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
unsigned short *IO = reinterpret_cast<unsigned short*>(0x8000);
unsigned short offset = static_cast<unsigned short>(0x2);
unsigned short *value = reinterpret_cast<unsigned short*>(IO+offset);
cout << "IO is " << hex << IO <<endl;
cout << "value is " << hex << value <<endl;
return 0;
}
The output for this case is: IO is 00008000, value is 00008004
I had expected value to be 00008002
If IO is not a pointer, I get the result I expected.
What is going on here?
Thanks to anyone with a helpful explanation.
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
unsigned short *IO = reinterpret_cast<unsigned short*>(0x8000);
unsigned short offset = static_cast<unsigned short>(0x2);
unsigned short *value = reinterpret_cast<unsigned short*>(IO+offset);
cout << "IO is " << hex << IO <<endl;
cout << "value is " << hex << value <<endl;
return 0;
}
The output for this case is: IO is 00008000, value is 00008004
I had expected value to be 00008002
If IO is not a pointer, I get the result I expected.
What is going on here?
Thanks to anyone with a helpful explanation.