Hacker News new | past | comments | ask | show | jobs | submit login

The claim was about `x[6]`, which does not appear in your program. The point is that `[]` is always bounds-checked, and the bounds-checking cannot be opted out of even with `unsafe`.



> The claim was about `x[6]`, which does not appear in your program.

That was C code. The rust code for that was provided by drran.

> The point is that `[]` is always bounds-checked, and the bounds-checking cannot be opted out of even with `unsafe`.

I don't think anyone is hung up on whether you use std::ops::Index or not. You can access arrays without bounds checks.


> You can access arrays without bounds checks.

By explicitly doing it so, in an operation that is easy to grep for, or in the case of a binary library, search for the symbol during the linking phase.

Something that is impossible to validate in C, unless one is using a custom compiler, like Apple is doing for iBoot firmware.


> By explicitly doing it so, in an operation that is easy to grep for, or in the case of a binary library, search for the symbol during the linking phase.

Most of the time, these operations will be inlined, so they will already be gone by the time it gets to the linker. The compiler phase is the latest point where they are still visible.


Better than in C where they are nowhere to be found, not even in source code.


https://news.ycombinator.com/item?id=27941675

>No. Unsafe Rust only gets to do three things that aren't related to the "unsafe" keyword itself.

>[...]

>Your C program is free to define x as an array with four elements and then access x[6] anyway - but Rust deliberately cannot do that. Not in Safe Rust, but also not in Unsafe Rust either.

>[...]

>In fact by default the Rust compiler would warn you, if you write unsafe { foo[z] = 0; } that unsafe isn't doing anything useful here and you should remove it. That array dereference either is or, if z is small enough, is not, an overflow, and either way unsafe makes no difference.


holy goalpost batman. you've moved them to the other side of the world.

what's next, you can't write 6[x] in rust but it's perfectly fine C, thus rust is inadequate?


You might want to re-read the conversation thread.

Hint: I am not tialaramex, and neither of us said anything against Rust in our comments.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: