C Bindings: Variables

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 attribute:

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/docs/syntax_and_semantics/c_bindings/variables.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部