Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

what I need is a language the can directly call c and cross language compile with c so I don't have to write c! especially that nasty pre processor. cause there so much good c libraries that I want to consume and they're only available in c!!!


LLVM languages can all natively link with C code, since any LLVM bytecode can directly call other LLVM bytecode. So Zig, C++, Obj-C, Swift and Rust can all be compiled together.

But C compatibility is everywhere. Almost every language has a FFI (foreign function interface) for C code. C interop shows up in every language because at the end of the day every language needs to be able to talk to the operating system. For example, to read and write files your language needs to call functions in libc (or equivalent). And that library is written in C.

So, Nodejs can call C via has native modules & NAPI. Java can call C through JNI. Ruby has the ffi gem. Python, Luajit, Go, C#, ... the list goes on. They all have a mechanism to call C code.

If you're looking for another language that can live alongside your C code, you can choose any.


However, one typically needs to write out a description of the “C” interface. And if the “C” header files are large it can be a lot of work. For example, I’m unaware of any complete Python bindings to the win32api, user32, kernel32, gdi32.


Can we use NAPI and JNI together to bridge Node and Java/Android applications


Can we use NAPI and JNI together to bridge nodejs and Java/Android


thank you so much! I didnt know that about LLVM. and I love Swift!!!


I use Julia for this. Its ccall facility is very handy for C FFI calls, and Julia itself is very fast and performant with just a bit of type annotation.

https://docs.julialang.org/en/v1/manual/calling-c-and-fortra...


julia is so nice! can’t believe I didn’t try this before! thank you very much



Calling C from rust is easy enough


Then you really want Nim.




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

Search: