Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The post is more of a quick-n-dirty (and rather trivial) proof of concept as the code includes only sporadical checks for allocation errors and then adds a hand-wavy disclaimer to improve it as needed.

E.g. in production code this

  if (!vec_ptr) // memory out
    abort();

  for (int i = 0; i < 10; i++)
    vec_push(int, &vec_ptr, i);
should really be

  if (!vec_ptr) // memory out
    abort();

  for (int i = 0; i < 10; i++)
    if (! vec_push(int, &vec_ptr, i))
      abort();
but it doesn't really roll of the tongue.


If this is in a library code, then I tend to disagree. As an user of a library, I would rather be able to handle errors the way I want, I do not want the library to decide this for me, so just return an error value, like "VEC_ERR_NOMEM", or whatever.


If all you do is call abort anyway, you do not need an interface that makes you test for errors.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: