Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Dec 2004 13:00:50 +0000
From:      Peter Edwards <peadar.edwards@gmail.com>
To:        Peter Jeremy <PeterJeremy@optushome.com.au>, Greg 'groggy' Lehey <grog@freebsd.org>, FreeBSD Architecture Mailing List <arch@freebsd.org>
Subject:   Re: Header files with enums instead of defines?
Message-ID:  <34cb7c8404122205002bd7de18@mail.gmail.com>
In-Reply-To: <20041222103844.GI801@straylight.m.ringlet.net>
References:  <20041222010143.GS53357@wantadilla.lemis.com> <20041222090855.GO79646@cirb503493.alcatel.com.au> <20041222103844.GI801@straylight.m.ringlet.net>

next in thread | previous in thread | raw e-mail | index | archive | help
> The Single Unix Specification goes to great pains to repeat over and
> over again that the error codes are 'symbolic constants', which IMHO
> may be taken to mean either a #define'd macro or an enum value.
> I, too, went to check with more than half a hunch that it would mandate
> that the error codes be macros, but it turned out it doesn't :)

But "errno" itself is "int", so even if the constants for the
individual errno values were defined by an enumeration, that type
information would be lost to the debugger when looking at errno
itself, defeating the original benefit of having the symbolic names
available in the debugger. As an alternative to Peter Jeremy's
suggestion of using a GDB macro, you could, of course, define a type
as:
typedef enum {
    err_EPERM = EPERM,
    err_ENOENT = ENOENT,
    /* .... */
} errno_t

Then within gdb:

Breakpoint 1, main (argc=1, argv=0xbfbfe55c) at e.c:21
21          int rc = write(-1, "X", 1);
(gdb) n
22          pause();
(gdb) p (errno_t)errno
$1 = err_EBADF
(gdb) 

(Note if you actually try this, you need to define at least one object
of the errno_t type in your program to generate the type in the
executable output.)

That should work in other symbolic debuggers beyond gdb.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?34cb7c8404122205002bd7de18>