docs(ffi-linkage): document extern/export linkage keywords (Phase 4)

This commit is contained in:
agra
2026-06-14 15:40:37 +03:00
parent 4101cbc3e7
commit a8e0a8961b
2 changed files with 46 additions and 0 deletions

View File

@@ -409,6 +409,18 @@ printf :: (fmt: [:0]u8, args: ..Any) -> i32 #foreign libc;
write_fd :: (fd: i32, buf: [*]u8, count: u64) -> i64 #foreign libc "write";
```
`extern` / `export` are the keyword surface for C linkage. `extern` is the modern
spelling of `#foreign` (import); `export` is its dual — define a function in sx and
expose it under the C ABI so C can call back in. Both imply `callconv(.c)` and take
the same optional `[LIB] ["csym"]` rename tail; they also apply to data globals and
to Obj-C / JNI runtime-class aggregates (postfix after the `#objc_class(…)` directive).
```sx
abs :: (x: i32) -> i32 extern; // import (== `#foreign`)
sx_square :: (x: i32) -> i32 export { x * x } // define + expose to C
__stdinp : *void extern; // extern data global
NSObject :: #objc_class("NSObject") extern { alloc :: () -> *NSObject; } // reference a runtime class
```
Direct C header import:
```sx
#import c {