Hacker News new | past | comments | ask | show | jobs | submit login

Ada does this with the rather convenient

  pragma Export(Convention => C, Entity => My_Ada_Function, External_Name => "mypackage_ada_function");
You can kinda coerce D and C++¹ to do the same thing, but this is definitely something Rust and Ada got really right.

--

¹Okay I lied, C++ does this pretty easily with extern "C". However, C++ APIs frequently do not convert well to C at all and you often have to write wrappers for them. C++ classes in particular just can't cross ABI boundaries without a lot of pain, while Ada records and Rust structs are usually just a pragma away from being accessible from C (their “methods” don't use a special calling convention; method calls are just syntactic sugar for passing a struct as the first argument).




The x86 C++ ABI convention of passing this in ECX probably caused a lot of C interop headaches over the years, but really, C should have been passing the first argument in a register anyway.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: