Search
 
SCRIPT & CODE EXAMPLE
 

RUST

armanriazi•rust•unsafe•extern•mangling

We also need to add a #[no_mangle] annotation to tell the Rust compiler not to mangle the name of this function. Mangling is when a compiler changes the name we’ve given a function to a different name that contains more information for other parts of the compilation process to consume but is less human readable. Every programming language compiler mangles names slightly differently, so for a Rust function to be nameable by other languages, we must disable the Rust compiler’s name mangling.

In the following example, we make the call_from_c function accessible from C code, after it’s compiled to a shared library and linked from C:



#![allow(unused)]
fn main() {
#[no_mangle]
pub extern "C" fn call_from_c() {
    println!("Just called a Rust function from C!");
}
}
Comment

PREVIOUS NEXT
Code Example
Rust :: $sce trust url 
Rust :: rust•armanriazi•error•value used here after move 
Rust :: overwritting print on same line rust 
Rust :: Counting bits Kernighan style 
Rust :: armanriazi•rust•type•recursive 
Rust :: rust sort vec of f64 
Rust :: armanriazi•rust•thread•multi•arc•mutex 
Rust :: armanriazi•rust•thread•spawning 
Rust :: rust sum and average of number list 
Rust :: create a rust project Inside the folder 
Rust :: split text on multiple separators and put into a list 
Lua :: roblox make a rainbow part 
Lua :: lua multiline comment 
Lua :: user input lua 
Lua :: luau how to loop through all players 
Lua :: forever loop in lua 
Lua :: roblox key pressed script 
Lua :: lua create file 
Lua :: replace part of string lua 
Lua :: get last characters of string lua 
Lua :: how to stop code roblo 
Lua :: draw circle love2d 
Lua :: int and float in lua 
Lua :: lua print table as string 
Lua :: how to activate a command if someone wears a accessory in lua roblox 
Matlab :: pyspark dense 
Matlab :: octave a:b:c range 
Basic :: what to include in basic C 
Elixir :: elixir catch 
Elixir :: .t() elixir 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =