File tree Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Original file line number Diff line number Diff line change 18
18
//! Considering the following code, operating on some global static variables:
19
19
//!
20
20
//! ```rust
21
- //! # static mut A: u32 = 0;
22
- //! # static mut B: u32 = 0;
23
- //! # static mut C: u32 = 0;
24
- //! # unsafe {
25
- //! A = 3;
26
- //! B = 4;
27
- //! A = A + B;
28
- //! C = B;
29
- //! println!("{} {} {}", A, B, C);
30
- //! C = A;
31
- //! # }
21
+ //! static mut A: u32 = 0;
22
+ //! static mut B: u32 = 0;
23
+ //! static mut C: u32 = 0;
24
+ //!
25
+ //! fn main() {
26
+ //! unsafe {
27
+ //! A = 3;
28
+ //! B = 4;
29
+ //! A = A + B;
30
+ //! C = B;
31
+ //! println!("{} {} {}", A, B, C);
32
+ //! C = A;
33
+ //! }
34
+ //! }
32
35
//! ```
33
36
//!
34
37
//! It appears _as if_ some variables stored in memory are changed, an addition
42
45
//! - first store to `C` might be moved before the store to `A` or `B`,
43
46
//! _as if_ we had written `C = 4; A = 3; B = 4;`
44
47
//!
45
- //! - last store to `C` might be removed, since we never read from it again.
46
- //!
47
48
//! - assignment of `A + B` to `A` might be removed, the sum can be stored in a
48
49
//! in a register until it gets printed, and the global variable never gets
49
50
//! updated.
You can’t perform that action at this time.
0 commit comments