镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
This repository was archived by the owner on Jun 6, 2021. It is now read-only.

Note: External Functions

alexrp edited this page Feb 28, 2013 · 2 revisions

External functions are declared like so:

pub fn ext "cdecl" my_public_fn() -> unit;
priv fn ext "cdecl" my_private_fn() -> unit;

pub fn ext "stdcall" my_stdcall_fn() -> unit;

pub fn ext "cdecl" my_cdecl_flect_fn() -> int {
    42;
}

priv fn ext "flect" my_flect_fn -> unit {
}

There are a few things worth noting here:

  • Visibility of an ext function does not have any effect on its name mangling or calling convention.
  • The flect calling convention is equivalent to not specifying any explicit calling convention with ext.
  • Specifying an unknown calling convention for a function is a semantic error.
  • Specifying an unsupported calling convention for the current target shall only be diagnosed if the function is actually called or used somehow.

Function pointer types are enhanced with an ext attribute:

let fptr : fn ext "cdecl"() -> unit = &my_public_fn;

A function pointer type with ext "flect" implicitly converts to the equivalent type without an explicit calling convention.

Clone this wiki locally