--- In [email protected], Sebastian Bertran <[EMAIL PROTECTED]> wrote:
>
> On Sun, 2008-07-27 at 16:31 +0530, saurabh jain wrote:
> > In the following line: 
> > "W64& mem = *(W64*)(W64)addr;"
> > 
> 
> addr is W64 too? then the cast is unnecessary.

Then why does the following code give a seg fault when I uncomment
"//W64& mem = *(W64*)(W64)addr;"  ?

typedef unsigned long long W64;
W64 mux64(W64 sel, W64 v0, W64 v1) {
        return (sel & v1) | ((~sel) & v0);
}

signed long long shift(unsigned long long add, int j)
{
        int i = 32;
        return (signed long long)((add << (i-j)) >> (i-j));
}

int main()
{
  W64 addr = 0x5a00, data = 15;
  addr = shift(addr, 48);
  //W64& mem = *(W64*)(W64)addr;
  W64& mem = addr;
  cout << " before " << mem << endl;
  mem = mux64(0xff, mem, data);
  cout << " after " << mem << endl;
  return data;
}


> 
> > Is it not equal to W64& mem = addr?
> > 
> Yes, if addr is W64.
> 

Thanks,
Saurabh

Reply via email to