Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> In this case you'd need to store that the max value is bufsize at an earlier point in the program, not the current value. A full implementation would get quite complicated quite quickly.

We're almost 1/4 into the 21st century. As someone that has attempted this as an exercise in C, please, just learn a little bit of Rust and move onto modern problems. The analogy I like to use is adjusting all the springs on a mattress vs buying a memory foam mattress and letting better material do its job.



I’m using rust and it’s not always clear how to solve this problem at compile time in this language either. If your array sizes are const then it’s doable but that’s only a subset of the usage because often arrays must have some known variable size.

Since you seem to know how to do it, can you please tell me how to check the bounds of the arrays at compile time if the actual underlying value is not known until runtime? I guess I could make a type-level algebraic field and add, subtract, multiply, divide my generics but this seems like a huge pain in the butt.

If anyone knows how to perform comptime algebraic bounds checking in stable rust lmk


I don't think that can ever be done with an array. Try with slices. They seem to be a fair alternative for most situations.




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

Search: