Re:Rust for C++ programmers – part 3: primitive types and op...
by dbaupp on Wednesday April 23, 2014 @02:19AM
(#7632453)
Indexing a fixed-length array (I.e. known at compile time) out of bounds is not prohibited at compile time. All array types trigger a task failure on out-of-bounds access (unless you explicitly opt-in to unchecked indexing).
[ Parent
| on HN ]
Re:Rust for C++ programmers – part 3: primitive types and op...
by guelo on Wednesday April 23, 2014 @02:40AM
(#7632514)
I was going to ask if array[random_integer()] would compile only some of the time.
Re:Rust for C++ programmers – part 3: primitive types and op...
by b0b_d0e on Wednesday April 23, 2014 @02:45AM
(#7632534)
Oh thanks for clearing that up! Is there any specific reason why the rust compilier currently doesn't check that a static int accessing into a known length slice doesn't result in a compile error? (I'm only referring to cases where the index you are trying to access is known at compile time as well as the length of the slice)
Re:Rust for C++ programmers – part 3: primitive types and op...
by nikbackm on Wednesday April 23, 2014 @03:31AM
(#7632651)
It would be inconsistent and not really that helpful. How often do you use (invalid) constant indexes with fixed length arrays?
Probably better to handle all out-of-bounds errors the same way.