Bounds Checking Debate

Discussions focus on bounds checking for array accesses in C, C++, and Rust, debating compile-time vs. runtime checks, compiler optimizations that eliminate them, and performance trade-offs.

📉 Falling 0.4x Programming Languages
2,515
Comments
18
Years Active
5
Top Authors
#6247
Topic ID

Activity Over Time

2009
7
2010
6
2011
13
2012
22
2013
34
2014
122
2015
119
2016
152
2017
145
2018
128
2019
201
2020
160
2021
156
2022
375
2023
296
2024
319
2025
241
2026
21

Keywords

readyset.io NULL ASSERT TechnicalTalks PtrWasDanglingError RawVec LLVM llvm.org CVE GCC bounds checking checks compiler compile time bound unsafe rust check compile

Sample Comments

teo_zero • Nov 24, 2024 • View on HN

What C compiler would add bounds checks?

loeg • Feb 4, 2024 • View on HN

Yeah, unless you bypassed the bounds checking with unsafe{} for performance reasons. (The is an unlikely place to do so.)

identity0 • Sep 13, 2020 • View on HN

You can't do compile time bounds checking, if that's what you're implying.

gridlockd • Nov 12, 2019 • View on HN

How would you enforce bounds checking while supporting unsafe languages?

haolez • Oct 16, 2022 • View on HN

You can enable bound checking when calling the compiler. I don't remember the actual command line flags, though.

e3b0c • Aug 22, 2016 • View on HN

I don't think bounds checking can be done at compile-time, especially in C/C++.

TwentyPosts • Aug 20, 2023 • View on HN

Remind me, how is this a good thing again? Especially considering that (if you write modern C++) the compiler should optimize away bound checks most of the time (and in all critical places) either way.

antiframe • Sep 26, 2023 • View on HN

Rusts bounds checking is done at compile time, so you don't need to turn it off.

Yoric • Feb 8, 2023 • View on HN

Out of curiosity, do you know projects with C code and bounds checks?

DCKing • Jun 12, 2014 • View on HN

It appears the compiler optimizes out bounds checking if and only if it can tell during compile time that the index is correct [1]. Arrays of dynamic size or with dynamic references are bound checked. In dynamic cases you should be writing manual bound checking guards in C anyway.[1]: https://github.com/mozilla/rust/issues/9024