Search docsSearch this language
Interoperability
Release candidatev0.20260809.0-rc.5

These docs describe the current coordinated release candidate.

Interoperability

Boundary data types

Use Go-compatible aggregate layouts, multi-value results, and GC-safe variants.

C2Go defines C representations for a small set of Go aggregate values. On 64-bit targets these layouts can cross the boundary by value.

Built-in aggregates

C type Go value 64-bit layout
c2go_slice []T data, length, capacity
c2go_string string data, length
c2go_iface interface table, data
c2go_error error same two words as interface

__c2go_intptr is the pointer-width signed Go int used in these definitions.

These values describe ABI layout, not the full Go language. C2Go currently provides no C syntax or helper API for dynamic interface-method dispatch through c2go_iface. Expose a named wrapper on the Go side and bind that static symbol with c2go_linkname instead.

Multi-value results

Use c2go_returntype with a complete struct when a Go function returns multiple values:

struct ReadResult {
    c2go_slice bytes;
    c2go_error error;
};

extern struct ReadResult go_read(c2go_string path)
    c2go_linkname("example.com/files.Read")
    c2go_returntype(struct ReadResult);

Each field maps to one Go result slot. The declaration’s return type must be exactly the annotated struct.

GC-compatible unions

c2go_variant requests a representation the Go GC can reason about:

union __attribute__((c2go_variant)) Number {
    int integer;
    float real;
};

The attribute applies only to unions. Overlapping pointer members that cannot be distinguished safely are rejected; it is not a license for arbitrary pointer punning.

For a searchable view of ordinary C syntax and C2Go-specific spellings, continue with the C language quick reference.