You cannot do that because some languages implementations could have an [ABI][1] different and incompatible with the C one.

On current systems, C is very common and most (but not all) language implementations have an ABI and [calling conventions][2] compatible with the one from C. Notice that it is a property of the implementation (your C compiler and your operating system), not of the programming language.

Also, some languages have different and incompatible views on [control flow][3] (look into [call/cc][4] and [tail-calls][5] in [Scheme][6], Goroutines in [Go][7], or backtracking and [cut operator][8] in [Prolog][9], [CLIPS][10] rules, concurrent actor languages, ....). I'm not sure you'll be able to design something which easily fits all of them (and that could impact the FFI requirements of implementation of these languages).


If using C++, beware of [name mangling][11] and of exception handling. (e.g. C `longjmp` is not friendly with C++ exceptions). [Dynamic loading][12] facilities like [`dlopen`][13] and [`dlsym`][14] are relevant to name mangling. So prefer an API using `extern "C"` functions. [libgccjit][15] could be inspirational (it is coded in C++ but has a C friendly API) and perhaps useful (you could consider runtime generation of glue code).

Memory management (notably with [garbage collection][16]) is also an issue. Study for examples [foreign function][17] interface [of Ocaml][18] and [of SBCL][19] and [of Lua][20] and of [Guile][21]. Look into [libffi][22]. Some languages also want [serialization][23] or [persistence][24] facilities (even for foreign data). Read also about [dynamic software updating][25].

You could provide some reflection facilities (e.g an API to query your API, e.g. like [GTK introspection][26]). You might try to provide a generic closure mechanism like [in  GObject][27]-s.

You could use (or customize or adapt) code generators like [SWIG][28]. You might consider compiler plugins (e.g. [GCC MELT][29] extensions).

## There is [**no silver bullet**][30].



<sup>NB. Better make your stuff [free software][31]. You might get outside contributions and you'll need outside help to interface your thing with many programming languages, including some that you don't even know. [Open source][32] is a good way to counter [leaky abstractions][33] (since you and other contributors can dive into the implementation source code). Given the variety of programming languages, **you will need *outside* help** (as soon as your API is successful)</sup>


  [1]: https://en.wikipedia.org/wiki/Application_binary_interface
  [2]: https://en.wikipedia.org/wiki/Calling_convention
  [3]: https://en.wikipedia.org/wiki/Control_flow
  [4]: https://en.wikipedia.org/wiki/Call-with-current-continuation
  [5]: https://en.wikipedia.org/wiki/Tail_call
  [6]: https://en.wikipedia.org/wiki/Scheme_(programming_language)
  [7]: https://en.wikipedia.org/wiki/Go_(programming_language)
  [8]: https://en.wikipedia.org/wiki/Cut_(logic_programming)
  [9]: https://en.wikipedia.org/wiki/Prolog
  [10]: https://en.wikipedia.org/wiki/CLIPS
  [11]: https://en.wikipedia.org/wiki/Name_mangling
  [12]: https://en.wikipedia.org/wiki/Dynamic_loading
  [13]: http://man7.org/linux/man-pages/man3/dlopen.3.html
  [14]: http://man7.org/linux/man-pages/man3/dlsym.3.html
  [15]: https://gcc.gnu.org/onlinedocs/jit/
  [16]: https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)
  [17]: https://en.wikipedia.org/wiki/Foreign_function_interface
  [18]: http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html
  [19]: http://sbcl.org/manual/index.html#Foreign-Function-Interface
  [20]: https://www.lua.org/manual/5.3/manual.html#4
  [21]: https://www.gnu.org/software/guile/learn/
  [22]: https://sourceware.org/libffi/
  [23]: https://en.wikipedia.org/wiki/Serialization
  [24]: https://en.wikipedia.org/wiki/Persistence_(computer_science)
  [25]: https://en.wikipedia.org/wiki/Dynamic_software_updating
  [26]: https://wiki.gnome.org/Projects/GObjectIntrospection
  [27]: https://developer.gnome.org/gobject/stable/gobject-Closures.html
  [28]: http://swig.org/
  [29]: http://gcc-melt.org/
  [30]: https://en.wikipedia.org/wiki/No_Silver_Bullet
  [31]: https://en.wikipedia.org/wiki/Free_software
  [32]: http://opensource.org/
  [33]: https://en.wikipedia.org/wiki/Leaky_abstraction