CEP-0040: Bodyless Foreign Function Declarations¶
Draft
Draft proposal for bodyless C-style foreign function declarations. V1 imports C functions as explicit function-pointer const values.
Summary¶
Catalyst should eventually decide whether foreign functions can be declared with bodyless fn declarations.
V1 uses @extern(.c) on explicit function-pointer const declarations.
Example¶
Possible future shape:
@extern(.c)
fn puts(text: *const u8) i32
V1 uses an explicit function-pointer constant instead:
@extern(.c)
const puts: *fn (*const u8) callconv(.c) i32
Motivation¶
Bodyless foreign declarations are familiar and concise, but they add a special declaration form and interact with linkage, ABI validation, reflection, and imports.
Proposed Direction¶
The proposal should cover:
- source syntax for bodyless foreign functions;
- required ABI and link-name metadata;
- whether the declaration has function item, function pointer, or special external function type;
- reflection and documentation behavior;
- diagnostics for unsupported signatures.
V1 Compatibility¶
V1 rejects bodyless C-like function declarations. Use @extern(.c) function-pointer constants.