Skip to content

Instantly share code, notes, and snippets.

@toothbrush7777777
Forked from luqmana/Entrypoints!.md
Last active April 9, 2017 18:28
Show Gist options
  • Save toothbrush7777777/0d5a478ef6e64c105f0a5be0cc7a7f0b to your computer and use it in GitHub Desktop.
Save toothbrush7777777/0d5a478ef6e64c105f0a5be0cc7a7f0b to your computer and use it in GitHub Desktop.

What do #![no_start], #![no_main], #[lang = "start"], #[start] and #[main] do?

#![no_start]

Disable automatically linking in the libnative crate and thus the default start language item.

This means you'll probably need #![no_main], #![lang = "start"] or #[start] instead.

Note: #![no_std] implies #![no_start].

#![no_main]

No main (entrypoint) function. You will want this if you’re linking with something that insists on providing main (such as SDL).

#[lang = "start"]

The function called from the actual entry point (real main). It is passed argc, argv and a pointer to the user’s main function (i.e fn main or whatever is marked with #[main]).

The default one in libnative sets up the runtime then calls your main.

Signature

fn (rust_main: *u8, argc: int, argv: **u8) -> int;

#[start]

Overrides the start lang item. It too is called from the actual entry point (real main). It is only passed argc and argv.

Signature:

fn (argc: int, argv: **u8) -> int;

Equivalent to:

#![no_main]

fn my_start(argc: int, argv: **u8) -> int {}

#[no_mangle]
extern "C" fn main(argc: int, argv: **u8) -> int {
    my_start(argc, argv)
}

#[main]

Let’s you mark a function as the main function (called by the start lang item).

Example

#[main]
fn whatever_I_want_to_call_this() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment