Header files with enums instead of defines?
M. Warner Losh
imp at bsdimp.com
Wed Dec 22 20:34:06 PST 2004
In message: <34cb7c84041222162210f14238 at mail.gmail.com>
Peter Edwards <peadar.edwards at gmail.com> writes:
: >
: > Or better yet, just use the array of error values already compiled
: > into the programs that strerror() formats for you (you don't need to
: > use strerror, just sys_errlist[]).
:
: I'd dispute the "better yet": If used in code, "errno_t" is useful in
: its own right. Even beyond the type safety, if used in a structure
You don't get type safety from C enums. They are, at best, a
lexically different #define. In C++ you have lots of other rules.
: > (gdb) print *structptr
:
: Will print errno_t members properly, without requiring hints that
: fields represent errno values, etc. (ie, it's a hint to the debugger
: that something of type errno_t conveys more specific information than
: a value between INT_MIN and INT_MAX.)
: Although textual descriptions are better than the errno names to
: users, "err_EBADF" means much more than "9" in a debug output to the
: programmer running the debugger.
:
: Sorry for splitting hairs. (But the bikeshed should definitely be blue)
I guess that's incompatible with what was said earlier in the
thread. you'd have to assign the errno_t to the integer errno or the
integer errno to an errno_t. That just doesn't work in C++.
Warner
More information about the freebsd-arch
mailing list