Link to home
Start Free TrialLog in
Avatar of rajiv11
rajiv11

asked on

understanding how union works

Ok here is a sample code that i dont understand. I use turboc compiler.

unsigned long BaseAddress1=0xC8000L;    //Default Base Address, transmitter
unsigned long BaseAddress2=0xC8100L;    //Default Base Address, receiverunsigned char far* NormAddress1;       //Base address in form SEGM:ADDR
unsigned char far* NormAddress2;       //Base address in form SEGM:ADDR
unsigned char far* NormAddress1;       //Base address in form SEGM:ADDR

union UAddrLng
{
      unsigned char far* Addr;
      unsigned long Numb;
}UAL;


unsigned char far* GetAddress ( unsigned long Ad)
{
      UAL.Numb=Ad;
      Ad&=0xF;
      UAL.Numb&=0xFFFF0l;
      UAL.Numb=(UAL.Numb<<12)|Ad;
      return UAL.Addr;
}

int main (int argc, const char *argv[])

{
      NormAddress1=GetAddress(BaseAddress1);
                printf("NormAddress1= %x",NormAddress1);
      NormAddress2=GetAddress(BaseAddress2);
}

I dont know how to display the unsigned char far* and unsigned long. Also dont understand how unions work. Tried looking online tutorial but got confused. So what does the function GetAddress  return?? thanks in advance.
SOLUTION
Avatar of NovaDenizen
NovaDenizen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial