8 ms·
Memory locality
- amboar 13y agoNot to detract from the interesting difference between pointers and unbounded arrays in a struct, but get_at() is surely broken. It looks like the condition uses the wrong inequality: int get_at(const struct foo_t *foo, int pos) { return foo->len >= pos ? -1 : foo->data[pos]; } !(foo->len >= pos) = (pos >= foo->len) => foo->data[pos] = foo->data[foo->len + x] where x >= 0, which is undefined. It seems the author got caught up trying to be tricky, and the fix has the bonus of reading more naturally: return (pos < foo->len) ? foo->data[pos] : -1; It is late though. Maybe my brain isn't in gear...