6 ms·
I don't think bounds checking can be done at compile-time, especially in C/C++.
by e3b0c 10y ago
I don't think bounds checking can be done at compile-time, especially in C/C++.
- XMPPwocky 10y agoNot in the general case. char x[4]; printf("%c", x[4]); That's pretty easy to detect.
- ithkuil 10y agohere you're talking about compile time bound check _elimination_, i.e. statically determine when you can remove a runtime bound check which would have been added by the compiler. I think e3b0c was talking about completely static bound checks.
- codys 10y agoNo. We can look at the example given above and clearly know/prove that the access is out of bounds. ie: a C compiler could emit a diagnostic (or decide it's undefined behavior and treat it as unreachable). There aren't any bounds checks above to eliminate.
- deleted 10y ago[deleted]