Why does my rust program initializing a large array on the stack die quietly?


I am brand new to Rust (< 3 days) but I’m sure that doing what I did is definitely not a good idea. However, I am curious as to why the program just terminates with no stack overflow or some other message right at the point of array initialization. I tried the following in my environment (stable v1.17.0) and in the Rust Playground with the same results:

fn main() {
    let obuf: [u8; 20000000] = [0; 20000000];
    println!("{}", obuf[0]);

If I make the size smaller, the program runs to completion and prints 0. If the size is too large, it seems to never get to the println! and dies with no message.

Thanks for your help


It’s a stack overflow, so your question is why no error message?




Yes, I was wondering why there was no error message on the stack overflow.


I just realized that when I run the executable directly from the command line it prints the seg fault message. I was doing ‘cargo run’ which did not print the message to the screen. Thanks