Compile (and call) a C function from Julia

I wonder if it would make sense that Julia enables one to call a C function described by its source code…
ccall("
#include <stdio.h>
int main()
{
// printf() displays the string inside quotation
printf(“Hello, World!”);
return 0;
}")

Cxx.jl has that function.

Thank you !!

Note that if you have a C compiler installed, you can invoke it an load the resulting code pretty easily from Julia. See e.g. the first example in:

https://github.com/stevengj/18S096/blob/master/lectures/lecture1/Boxes-and-registers.ipynb

2 Likes

Thank you very much for the link ! The conciseness of the C function build looks like blackmagic :open_mouth: I should add this one to Sum performance for Array{Float64,2} elements - #14 by LaurentPlagne benchmark curves (I think I remember that gcc did not perform very well on that specific loop).