← All examples

C headers

incl.C.system["…"] reads the system's headers while building, so C's functions need no hand-written extern.C.

c_headers.zg
# C headers (owner, 2026-10-10): `incl.C.system["…"]` reads the system's headers while building, so C's
# functions need no hand-written `extern.C`. A header brings its functions, globals and plain `#define`
# constants (`'BUFSIZ'`); they are called bare where the line is, or with a module's prefix when the
# line sits in a `module` block (`pub.strike` there, as for any item a module shares). A call into C
# is a `no_check` site, as for `extern.C`. The oracle runs only the C functions it imitates (write,
# strlen, getenv, malloc, free, exit, qsort).
incl.C.system["unistd.h", "stdio.h"];

module text { pub.strike incl.C.system["string.h"]; }

MAIN {
    let 'msg' := "hello through C's write";
    no_check let 'n' := write[1, lend 'msg', text.strlen[lend 'msg']];
    std::print.useful[newln, 'n', " bytes; BUFSIZ ", 'BUFSIZ', ", EOF ", 'EOF', ", SEEK_END ", 'SEEK_END', newln];
}
Output
hello through C's write
23 bytes; BUFSIZ 1024, EOF -1, SEEK_END 2