< 返回我的博客

name 发表于 2018-01-25 02:52

#![feature(pointer_methods)] #[derive(Debug)] struct A{ num:i32 } fn main() { let mo=A{ num:32 }; let mo_point=&mo as *const A; let mut b=mo; // println!("{:?}",mo); mo move let b_point=&b as *const A; println!("b_point :{:?}",b_point);//b_point :0xf9ae0ff9e4 println!("mo_point:{:?}",mo_point);//mo_point:0xf9ae0ff9d4 let b_mut_point =&mut b as *mut A; unsafe { println!("mo_point.read():{:?}",mo_point.read());//mo_point.read():A { num: 32 } println!("b_point.read: {:?}",b_point.read());//b_point.read: A { num: 32 } println!("b :{:?}",b);// b :A { num: 32 } b_mut_point.write(A{num:2});//修改 println!("after b:{:?}",b);// after b:A { num: 2 } println!("after mo_point:{:?}",mo_point.read());//after mo_point:A { num: 32 } //?上面输出的不是A { num: 2 } 求解????????????

    println!("after b_point :{:?}",b_point.read());//after b_point :A { num: 2 }
}

}

评论区

写评论

还没有评论

1 共 0 条评论, 1 页