3 ms·
> reading past the end of an array will always segfault the program immediately. or reading past the end of an array will return (arrayType)0 How would this wo
by timmytokyo 11y ago
> reading past the end of an array will always segfault the program immediately. or reading past the end of an array will return (arrayType)0
How would this work when you pass the array (i.e., the pointer) to a function? In order to do what you describe, every pointer would need to include bounds information. This would break the C ABI, so your code would no longer link with existing C libraries.
- raverbashing 11y agoExactly. It can't C makes you take the needed metadata to other parts of the program manually. It's not about being low-level, it's about having "pretend types" (like string or array) that are only actually a pointer with a tiny bit of syntactic sugar.
- sanxiyn 11y agoOP answered this on the thread. Pointer bounds are stored in a lookup table. Pointers are passed to functions according to C ABI, and bounds are retrieved by querying the lookup table by the pointer.