StructOp Handbook
Contents Examples Commands

Lib libc

Console program90 lines of .st191 lines of generated C
Program output
sorted: 1 3 5 7 9
abs: 42
atoi: 123
STRUCTOP_SEED: 1
On this page

The .st files#

intent.st
structop {
    type_app {
        exec = {
            lang     = "C"
            standard = "c11"
        }
    }

    lib_provider {
        C_lang = {
            source  = "StructOp/c"
            version = "@latest"
        }
        Libc = {
            source  = "C/libc"
            version = "@latest"
        }
    }
}

Input, plan and generated C#

bind/libc.bind.st · hints for structop bind
bind/libc.bind.st · hints for structop bind
# The C standard library: macOS and Linux spell these parameters differently (or not at all),
# so names gives every kept function the same attribute names on both.
bind "libc" {
    header  = "stdlib.h"
    version = "1.0.0"
    prefix  = ["qsort", "abs", "atoi", "getenv"]
    skip    = ["qsort_r", "qsort_b", "getenv_r"]
}

function "qsort" {
    names     = ["base", "count", "width", "compar"]
    array     = [{ data = "base", count = "count", size = "width", of = Int32 }]
    points_to = Int32
}

function "abs" {
    names = ["value"]
}

function "atoi" {
    names = ["text"]
}

function "getenv" {
    names        = ["name"]
    returns_text = "library"
}
structop plan
structop plan
  # program.app will be created
  + program.app (.structop/build/app)
      + ability.value.nums
      + ability.value.n
      + ability.value.seed
      + ability.qsort.Sort
      + ability.print.Sorted
      + ability.abs.Abs
      + ability.print.ShowAbs
      + ability.atoi.Atoi
      + ability.print.ShowAtoi
      + ability.getenv.Seed
      + ability.print.ShowSeed

Plan: 1 to add, 0 to change, 0 to destroy.
Generated main.c

To inspect this generated file, select C in intent.st, initialize the project and export its source.

Export locally
structop init
structop apply -source -no-run
Try it
structop bind bind/libc.bind.st    # from the repository root
cd lib-libc    # a folder holding the .st files above
structop init
structop plan
structop apply