Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #[inline(never)]
  2. fn borrows(input: &u32, output: &mut u32)
  3. {
  4. if *input > 10
  5. {
  6. *output = 2;
  7. }
  8. if *input > 5
  9. {
  10. *output *= 2;
  11. }
  12. }
  13.  
  14. #[inline(never)]
  15. fn ptrs(input: *const u32, output: *mut u32)
  16. {
  17. unsafe
  18. {
  19. if *input > 10
  20. {
  21. *output = 2;
  22. }
  23. if *input > 5
  24. {
  25. *output *= 2;
  26. }
  27. }
  28. }
  29.  
  30. #[inline(never)]
  31. fn mixed(input: *const u32, output: *mut u32)
  32. {
  33. let input = unsafe { &*input };
  34. let output = unsafe { &mut*output };
  35. if *input > 10
  36. {
  37. *output = 2;
  38. }
  39. if *input > 5
  40. {
  41. *output *= 2;
  42. }
  43. }
  44.  
  45.  
  46. fn main() {
  47. let borrows_value = 15;
  48. let ptrs_value = 15;
  49. let mixed_value = 15;
  50.  
  51. borrows(&borrows_value, unsafe { &mut*(&borrows_value as *const _ as *mut _) });
  52. ptrs(&ptrs_value, &ptrs_value as *const _ as *mut _);
  53. mixed(&mixed_value, &mixed_value as *const _ as *mut _);
  54.  
  55. dbg!(borrows_value);
  56. dbg!(ptrs_value);
  57. dbg!(mixed_value);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement