File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 13
13
- [ Packed SIMD vectors] ( ./layout/packed-simd-vectors.md )
14
14
- [ Validity] ( ./validity.md )
15
15
- [ Unions] ( ./validity/unions.md )
16
+ - [ Function Pointers] ( ./validity/function-pointers.md )
16
17
- [ Optimizations] ( ./optimizations.md )
17
18
- [ Return value optimization] ( ./optimizations/return_value_optimization.md )
Original file line number Diff line number Diff line change
1
+ # Validity of function pointers
2
+
3
+ ** Disclaimer** : This chapter is a work-in-progress. What's contained here
4
+ represents the consensus from issue [ #72 ] . The statements in here are not (yet)
5
+ "guaranteed" not to change until an RFC ratifies them.
6
+
7
+ A function pointer is "valid" (in the sense that it can be produced without causing immediate UB) if and only if it is non-null.
8
+
9
+ That makes this code UB:
10
+
11
+ ``` rust
12
+ fn bad () {
13
+ let x : fn () = unsafe { mem :: transmute (0usize ) } // This is UB!
14
+ }
15
+ ```
16
+
17
+ However, any integer value other than NULL is allowed for function pointers:
18
+
19
+ ``` rust
20
+ fn good () {
21
+ let x : fn () = unsafe { mem :: transmute (1usize ) } // This is not UB.
22
+ }
23
+ ```
24
+
25
+ [ #72 ] : https://github.com/rust-lang/unsafe-code-guidelines/issues/72
You can’t perform that action at this time.
0 commit comments