Interoperability with C
๋ฌ์คํธ๋ C ํธ์ถ๊ท์ฝ๊ณผ ํจ๊ป ๊ฐ์ฒด ํ์ผ์ ์ฐ๊ฒฐํ๋ ๊ฒ์ ์๋ฒฝํ๊ฒ ์ง์ํฉ๋๋ค. ๋ฐ๋๋ก ๋ฌ์คํธ ํจ์๋ฅผ ๋ด๋ณด๋ด์ C์์ ํธ์ถ ํ ์ ์์ต๋๋ค.
์ํ๋ ๊ฒฝ์ฐ ์ง์ ์ฝ๋ฉํ ์ ์์ต๋๋ค:
Rust has full support for linking object files with a C calling convention. Similarly, you can export Rust functions and call them from C.
You can do it by hand if you want:
extern "C" { fn abs(x: i32) -> i32; } fn main() { let x = -42; let abs_x = unsafe { abs(x) }; println!("{x}, {abs_x}"); }
์ฐ๋ฆฌ๋ ์ด๋ฏธSafe FFI ๋ํผ ์ฐ์ต๋ฌธ์ ์์ ์ด๋ฅผ ๋ค๋ฃจ์์ต๋๋ค.
์ด๋ ๋์ ํ๋ซํผ์ ๋ํ ์์ ํ ์ง์์ ์ ์ ๋ก ํฉ๋๋ค. ์ค ์ ํ์๋ ๊ถ์ฅํ์ง ์์ต๋๋ค.
๋ค์์ผ๋ก ์ข ๋ ๋์ ์ต์ ์ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
We already saw this in the Safe FFI Wrapper exercise.
This assumes full knowledge of the target platform. Not recommended for production.
We will look at better options next.