File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ E0014: include_str!("./error_codes/E0014.md"),
2323E0015 : include_str!( "./error_codes/E0015.md" ) ,
2424E0016 : include_str!( "./error_codes/E0016.md" ) ,
2525E0017 : include_str!( "./error_codes/E0017.md" ) ,
26+ E0018 : include_str!( "./error_codes/E0018.md" ) ,
2627E0019 : include_str!( "./error_codes/E0019.md" ) ,
2728E0023 : include_str!( "./error_codes/E0023.md" ) ,
2829E0025 : include_str!( "./error_codes/E0025.md" ) ,
Original file line number Diff line number Diff line change 1+ #### Note: this error code is no longer emitted by the compiler.
2+
3+ The value of static and constant integers must be known at compile time. You
4+ can't cast a pointer to an integer because the address of a pointer can vary.
5+
6+ For example, if you write:
7+
8+ ``` compile_fail,E0658
9+ static MY_STATIC: u32 = 42;
10+ static MY_STATIC_ADDR: usize = &MY_STATIC as *const _ as usize;
11+ static WHAT: usize = (MY_STATIC_ADDR^17) + MY_STATIC_ADDR;
12+ ```
13+
14+ Then ` MY_STATIC_ADDR ` would contain the address of ` MY_STATIC ` . However,
15+ the address can change when the program is linked, as well as change
16+ between different executions due to ASLR, and many linkers would
17+ not be able to calculate the value of ` WHAT ` .
18+
19+ On the other hand, static and constant pointers can point either to
20+ a known numeric address or to the address of a symbol.
21+
22+ ```
23+ static MY_STATIC: u32 = 42;
24+ static MY_STATIC_ADDR: &'static u32 = &MY_STATIC;
25+ const CONST_ADDR: *const u8 = 0x5f3759df as *const u8;
26+ ```
27+
28+ This does not pose a problem by itself because they can't be
29+ accessed directly.
You can’t perform that action at this time.
0 commit comments