News for hackers. Stuff that matters.
Re:Modern C [pdf] by ape4 on Monday November 28, 2016 @11:46AM (#13056574)
This looks fine to me. I wonder if C/C++ could be improved by introducing a new keyword `bail` which is the same as `goto` but is only allowed to jump to the bottom of the function. That way, codebases can outlaw `goto` but keep `bail`.
Re:Modern C [pdf] by 72deluxe on Monday November 28, 2016 @12:19PM (#13056828)
Are you looking for "return"?

With C++ you can ensure that you have your destructors do the tidy up, e.g. a messy example

struct cleaner { cleaner(string *toCleanup) : m_x(toCleanup) { } ~cleaner() { delete m_x; m_x = nullptr; } };

Re:Modern C [pdf] by ape4 on Monday November 28, 2016 @01:01PM (#13057153)
Yup, C++ has autocleanup. Of course if you are using fopen() instead something more modern you'll need to fclose(). Adding a new keywords to C is a long shot. Perhaps compilers could detect non-cleanup use of goto and give it a warning.
Re:Modern C [pdf] by int_19h on Monday November 28, 2016 @04:56PM (#13058772)
A typical C++ codebase I'm working on these days would have scope guards implemented via macros, such that you can do e.g.:

    FILE* f = fopen(...);
    SCOPE_GUARD({ fclose(f); });
This is mainly used for one-off calls to some native API, where writing a proper RAII wrapper for the managed resource is not worth it.
Re:Modern C [pdf] by krylon on Monday November 28, 2016 @02:44PM (#13057827)
In a previous job where I wrote C code, I had a macro named "bail" that pretty much did that: log an error message, then jump to the cleanup section of the function.
Re:Modern C [pdf] by flukus on Monday November 28, 2016 @06:58PM (#13059499)
Wouldn't it be better to have some sort of linter tool do this? Why create a more specific language construct when you already have one?