3 ms·
Writing a Dynamic Array in C
- hardware2win 3y agoIm relatively new to C and I struggle to understand why C std lib sucks so hard Why ppl need to write such a fundamental stuff like this? >void *vec_safe_at >return (t_index >= vec_length(self)) ? NULL : vec_at(self, t_index); Ehh, sadly we dont have generics in C and some improvements over NULL oriented programming
- keikobadthebad 3y agoIt's 50+ years old, it's amazing it's still so relevant and effective.
- hardware2win 3y agoI disagree It is just small, but not amazing and effective. Debugging index out of bound issues that could have been easily prevented sucks and wastes a lot of time
- keikobadthebad 3y ago> (self).elements = (void )malloc(sizeof(void ) t_capacity); assert(self->elements); 1) assert() only blows on _DEBUG builds 2) running out of memory for the process to allocate is a natural, normal thing, eg, maybe caused by VM or other limits. It shouldn't cause your process to terminate in an uncontrolled way