You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-12-23 23:12:52 +02:00
Publish Comprehensive Rust 🦀
This commit is contained in:
17
src/unsafe/extern-functions.md
Normal file
17
src/unsafe/extern-functions.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Calling External Code
|
||||
|
||||
Functions from other languages might violate the guarantees of Rust. Calling
|
||||
them is thus unsafe:
|
||||
|
||||
```rust,editable
|
||||
extern "C" {
|
||||
fn abs(input: i32) -> i32;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
// Undefined behavior if abs misbehaves.
|
||||
println!("Absolute value of -3 according to C: {}", abs(-3));
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user