Purpose of Go import C and Rust equivalent mechanism
This tests FFI entry points: Go's import "C" activates cgo to reference C symbols directly, while Rust uses an unsafe extern "C" block to declare external functions. A red flag is calling either a normal import or omitting unsafe in Rust.
This tests FFI boundary knowledge in systems languages. In Go, import "C" is the pseudo-package that enables cgo; a preceding comment becomes the C preamble for headers and directives, letting Go reference C.size_t or C.putchar directly. In Rust, you declare intent with an unsafe extern "C" block containing function signatures without bodies, which the linker resolves, and every call site must be inside unsafe. A red flag is treating Go's import as a normal package or describing Rust FFI as a safe import without unsafe blocks.
Read the original → pkg.go.dev
- #go
- #rust
- #ffi
- #cgo
- #interoperability
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.