QuantumC

C Interop

Back to home

QuantumC uses the C ABI for external interoperability.

There are two directions:

1. Export QuantumC code

To expose QuantumC functions to other languages through the C ABI:

extern:
int add(int a, int b) {
    return a + b;
}
:extern

This is equivelant to

extern "C" {
    int add(int a, int b) {
        return a + b;
    }
}

in many other languages.

2. Import external functions

To use functions provided by an external C ABI-compatible library or file:

foreign:
int add(int a, int b);
:foreign

This is like puting signatures in a extern "C" in other languages.