docs(ffi-linkage): document extern/export linkage keywords (Phase 4)
This commit is contained in:
12
readme.md
12
readme.md
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user