ABI - Use Rust code from C

I just followed “The Rust Reference: 17. Application Binary Interface (ABI)” and “The Embedded Rust Book: 10.2 A little Rust with your C” After then, I tried to expose Rust program to C as ABI. Test the code in the first reference foo.rs: // This is kept because of `#[used]`: #[used] static FOO: u32 = 123; // This is removable because it is unused: #[allow(dead_code)] static BAR: u32 = 0; // This is kept because it is publicly reachable: pub static BAZ: u32 = 0; // This is kept because it is referenced by a public, reachable function: static QUUX: u32 = 0; pub fn quux() -> &'static u32 { &QUUX } // This is removable because it is referenced by a private, unused (dead) function: static CORGE: u32 = 0; #[allow(dead_code)] fn corge() -> &'static u32 { &CORGE } used attribute The attribute can only be applied to static item.

Memory allocation in Rust

While learning “15.3. Running Code on Cleanup with the Drop Trait” of the Rust official book, I just wondered the memory layout of Rust program. TL;DR: Currently the default global allocator is unspecified. Libraries, however, like cdylibs and staticlibs are guaranteed to use the System by default. Struct std::alloc::System: The default memory allocator provided by the operating system. This is based on malloc on Unix platforms and HeapAlloc on Windows, plus related functions.