fschutt/azul

What's the deal with `extern "C"`?

iMplode-nZ opened this issue · 1 comments

I notice that the rust example requires extern "C". Would it be possible to have a separate rust api such that this isn't necessary, as Azul seems to be written in rust?

Edit: Some of the examples seem to not require extern "C". I can't tell which is true though.

Would it be possible to have a separate rust api such that this isn't necessary, as Azul seems to be written in rust?

Azul is written in Rust, but everything has to go through a C FFI layer, so that there is one binary interface for C, C++ and Rust. Every callback requires extern "C", otherwise passing callbacks would not be possible from C and C++. Rusts default extern "Rust" callbacks are not ABI-stable, they may change between different compiler versions. As such, they are only useful in statically-linked code (azul is usually dynamically linked).

All extern "C" functions are callbacks. The examples that don't require extern "C" are likely just outdated. This can't be changed because that's how the C ABI works.