]> git.lizzy.rs Git - rust.git/blob - example/alloc_example.rs
Merge pull request #1100 from mominul/trans->codegen
[rust.git] / example / alloc_example.rs
1 #![feature(start, box_syntax, alloc_system, core_intrinsics, alloc_prelude, alloc_error_handler)]
2 #![no_std]
3
4 extern crate alloc;
5 extern crate alloc_system;
6
7 use alloc::prelude::v1::*;
8
9 use alloc_system::System;
10
11 #[global_allocator]
12 static ALLOC: System = System;
13
14 #[link(name = "c")]
15 extern "C" {
16     fn puts(s: *const u8) -> i32;
17 }
18
19 #[panic_handler]
20 fn panic_handler(_: &core::panic::PanicInfo) -> ! {
21     core::intrinsics::abort();
22 }
23
24 #[alloc_error_handler]
25 fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
26     core::intrinsics::abort();
27 }
28
29 #[start]
30 fn main(_argc: isize, _argv: *const *const u8) -> isize {
31     let world: Box<&str> = box "Hello World!\0";
32     unsafe {
33         puts(*world as *const str as *const u8);
34     }
35
36     0
37 }