Created
April 20, 2019 04:45
-
-
Save anirudhb/c1e72a838b76d946d6879e54a80bc6fa to your computer and use it in GitHub Desktop.
Rust 1.34 Tiny hello world, comparable to C version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tiny "Hello, World!" program in Rust. | |
#![feature(no_core, lang_items)] | |
#![no_std] | |
#![no_core] | |
#![no_main] | |
#[lang = "panic_info"] | |
struct PanicInfo {} | |
#[panic_handler] | |
fn panic(info: &PanicInfo) -> ! { loop {} } | |
#[lang = "eh_personality"] | |
extern fn eh_personality() {} | |
#[lang = "sized"] | |
trait Sized {} | |
#[lang = "copy"] | |
trait Copy {} | |
#[lang = "freeze"] | |
unsafe trait Freeze {} | |
#[link(name = "c")] | |
extern "C" { | |
fn write(fd: i32, buf: *const i8, count: usize) -> isize; | |
fn exit(status: i32) -> !; | |
} | |
#[no_mangle] | |
pub unsafe extern "C" fn main() -> ! { | |
let s = b"Hello, World!\n"; | |
write(1, s as *const u8 as *const i8, 14); | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For x86_64-pc-windows-gnu in windows, line 20
#[link(name = "c")]
should be deleted to compile correctly.