alias

An alias declaration inside a lib declares a C typedef:

  1. lib X
  2. alias MyInt = Int32
  3. end

Now Int32 and MyInt are interchangeable:

  1. lib X
  2. alias MyInt = Int32
  3. fun some_fun(value : MyInt)
  4. end
  5. X.some_fun 1 # OK

An alias is most useful to avoid writing long types over and over, but also to declare a type based on compile-time flags:

  1. lib C
  2. {% if flag?(:x86_64) %}
  3. alias SizeT = Int64
  4. {% else %}
  5. alias SizeT = Int32
  6. {% end %}
  7. fun memcmp(p1 : Void*, p2 : Void*, size : C::SizeT) : Int32
  8. end

Refer to the type grammar for the notation used in alias types.