all 42 comments

sorted by: hot top controversial new old
[–] 49 points 2 years ago

Unsafe block detected. Extermination initiated. There is no hiding from memory safety!

  • source
  • [–] 39 points 2 years ago (1 child)

    Personally,

    echo Hello World!
    
  • source
  • hideshow 2 child comments
  • [–] 31 points 2 years ago (1 child)
    use std::process::Command;
    
    fn main() {
        Command::new("sh")
            .arg("-c")
            .arg("echo Hello World!")
            .spawn()
            .unwrap();
    }
    

    Like this?

  • source
  • parent
  • hideshow 2 child comments
  • [–] 10 points 2 years ago (2 children)

    No, more like

    use std::process::Command; fn main() { Command::new("sh").arg("-c").arg("echo Hello World!").spawn().unwrap(); }
    

    .
    Just a little bit shorter, as it seems /s

  • source
  • parent
  • hideshow 4 child comments
  • [–] [S] 2 points 2 years ago (1 child)
  • [–] 1 point 2 years ago

    Yes and no. While coreutils does provide an echo binary, shells also have a built-in for optimisation purposes.

    At first I had the code calling the binary directly, but then changed it to spawning a shell (and so using the builtin). It's very cursed either way.

  • source
  • parent
  • [–] 20 points 2 years ago (1 child)

    Oh you fancy PC people and your fancy syscall instruction.

    I still don't know why I could remember jsr $ab1e. I didn't even write that much assembly.

  • source
  • hideshow 2 child comments
  • [–] 19 points 2 years ago

    Or, you could just go the whole hog. Create your own simple CPU emulator, design a basic 8bitesque CPU, give it an output port that is the console, and load up some basic ASM to cycle through Hello World to the console port.

  • source
  • [–] 17 points 2 years ago

    Console.WriteLine("Hello World!");

  • source
  • [–] 17 points 2 years ago

    System.out.println

  • source
  • [–] 15 points 2 years ago

    echo "Hello world"

    This is different from the other two echos here, this is Nim not Bash.

  • source
  • [–] 14 points 2 years ago* (last edited 2 years ago) (1 child)

    Definitely left. Right one won't be optimized. (And there are so many some mistakes in your inline asm...)

  • source
  • hideshow 2 child comments
  • [–] [S] 1 point 2 years ago (1 child)
  • [–] 6 points 2 years ago (1 child)

    Mostly the missing listing of clobbered registers. Other than that it's mostly just that you're doing useless things, like manually putting the stuff into the registers instead of letting the compiler do it, and the useless push and pop. And the loop is obviously not needed and would hurt performance if you do every write like that.

    asm!(
    "syscall",
    in("rax") 1,
    in("rdi") 1,
    in("rsi") text_ptr,
    in("rdx") text_size,
    
    )
    

    ("so many" was inappropriate, sorry.)

  • source
  • parent
  • hideshow 2 child comments
  • [–] [S] 1 point 2 years ago (1 child)

    I am hopeless at getting the text_ptr simpler than i64::from_str_radix(&format!("{:p}", my_string)[2..], 16).unwrap(); How can i get it the normal way?

  • source
  • parent
  • hideshow 2 child comments
  • [–] 8 points 2 years ago
    [–] 8 points 2 years ago*

    console.log("Hello World!")

  • source
  • [–] 7 points 2 years ago
    def main(): 
        print("Hello world") 
    
  • source
  • [–] 5 points 2 years ago*

    Ec Emm this side is the best one ....

    ++++++++[< +++++++++>-]<. ++++[<+++++++>-]<+. +++++++.. +++.

    ++++++[<+++++++>-]<++. ------------. ++++++[<+++++++++>-]<+. <. +++. ------. --------.

    ++++[<++++++++>-]<+.

  • source
  • [–] 5 points 2 years ago* (last edited 2 years ago)
    #include &lt;stdio.h>
    
    int main(int argc, char** argv)
    {
        printf("hello, world");
    }
    
  • source
  • [–] 4 points 2 years ago (1 child)

    Why do you call write() for every char? You can always just pass a pointer with its length.

  • source
  • hideshow 2 child comments
  • [–] 4 points 2 years ago* (last edited 2 years ago) (2 children)

    plan 9 cat vs GNU longcat meme

    edit: reddit image linking is broken?

  • source
  • hideshow 4 child comments
  • [–] 4 points 2 years ago (2 children)

    Well, the GNU version does more and is more documented. The Plan9 code is frankly shitC, even for 1980z

    But this monstrosity is something else

  • source
  • parent
  • hideshow 4 child comments
  • [–] 2 points 2 years ago (2 children)

    reddit image linking is broken?

    Well you didn't link to a reddit image, you linked to Google image search result page which is not an image.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 0 points 2 years ago (1 child)

    I did that because the image didn't show in reddt.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 4 points 2 years ago

    ? "Hello World"

  • source
  • [–] 3 points 2 years ago
    echo Hello World
    
  • source
  • [–] 3 points 2 years ago

    Camel case?

    this_is_not_going_to_be_a_serious_debate

  • source
  • [–] 3 points 2 years ago* (last edited 2 years ago)

    dc <<<'10435358689859 70511561 11297399 23 5 3 2 ******P'

    note: lemmy's "smart quotes" vs its input sanitization required me to code-format the second half of that line (and not the first half) to make it copy+paste runnable.

  • source
  • [–] 3 points 2 years ago

    I thought the whole point of rust macros was to abstract away the scary asm at zero cost!

  • source
  • [–] 1 point 2 years ago

    Hello, world!

  • source
  • [–] 0 points 2 years ago*

    base64 -d <<<SGVsbG8gV29ybGQhCg==

  • source