Variables

Variables exposed by a C library can be declared inside a lib declaration using a global-variable-like declaration:

lib C
  $errno : Int32
end

Then it can be get and set:

C.errno # => some value
C.errno = 0
C.errno # => 0

A variable can be marked as thread local with an annotation:

lib C
  @[ThreadLocal]
  $errno : Int32
end

Refer to the type grammar for the notation used in external variables types.

To the extent possible under law, the persons who contributed to this workhave waived
all copyright and related or neighboring rights to this workby associating CC0 with it.
https://crystal-lang.org/reference/syntax_and_semantics/c_bindings/variables.html