1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
//microsoft visual C++ 2010
#include<iostream>
#include<string>
using namespace std;
struct tagIF
{
string binary;
struct tagEA //nested struct
{
string reg,mode;
}EA,*pEA;
};
struct tagCLR : tagIF
{
string DEF,B,W,L;
tagCLR():DEF("01000010"), B("00"), W("01"), L("10") {}
}CLR;
void main()
{
CLR.EA.mode="010";
CLR.EA.reg="101";
CLR.binary = CLR.DEF + CLR.B + CLR.EA.mode + CLR.EA.reg;
cout<<hex<<strtol(&CLR.binary[0],0,2)<<"h\n\n";
CLR.pEA->mode="010"; //compile: OK , run: processor fault
CLR.pEA->reg="101"; //compile: OK , run: processor fault
CLR.binary = CLR.DEF + CLR.B + CLR.pEA->mode + CLR.pEA->reg;
cout<<hex<<strtol(&CLR.binary[0],0,2)<<"h\n\n";
}
|