3 ms·
A quick question item 13 (table-style formatting): the author proposes something like this: static bool IsInterestingError(int errno) { ... } ... if (!Is
by YSFEJ4SWJUVU6 10y ago
A quick question item 13 (table-style formatting): the author proposes something like this:
static bool IsInterestingError(int errno) { ... }
...
if (!IsInterestingError(errno)) { ... }
Can you do that in a single file – assuming the latter errno is the one defined in errno.h (or cerrno). I was of the impression that errno may also be a macro, so could you say it's a good recommendation to have it as an argument's name – or in general even to reuse the name anywhere?
I agree that the option (of passing the helper function no arguments at all) is not perfect either, but... (I also don't like that you need to call your stored errno's errnums or the like, but that's what we have.)
- acqq 10y agoIf errno can be a macro, as at least one man page claims, the argument in the function could expand and even not compile or produce something unwanted. I'd prefer: static bool IsInterestingError(int e) { ... } http://man7.org/linux/man-pages/man3/errno.3.html http://man7.org/linux/man-pages/man3/errno.3.html
- wahern 10y agoerrno is a macro on most (maybe every) platform supporting pthreads. Furthermore, C11 literally defines errno as a macro in 7.5p1: The macros are EDOM EILSEQ ERANGE which expand to integer constant expressions with type int, distinct positive values, and which are suitable for use in #if preprocessing directives; and errno which expands to a modifiable lvalue that has type int and thread local storage duration, the value of which is set to a positive error number by several library functions. If a macro definition is suppressed in order to access an actual object, or a program defines an identifier with the name errno, the behavior is undefined. Notably, C11 introduced an optional threading API, effectively derived from the common functionality between Window's threading API and POSIX pthreads. While I can imagine ways to have a unique errno symbol that doesn't rely on macros, the obvious solution does and there's little reason not to use it. While C11 is most definitely not the same thing as C++11, I think, similar to atomics, the committees cooperated on the threading API. I don't have a recent C++ standard handy at the moment, but I wouldn't be surprised if C++11 at least allowed defining errno as a macro.