Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Dec 2004 20:08:55 +1100
From:      Peter Jeremy <PeterJeremy@optushome.com.au>
To:        "Greg 'groggy' Lehey" <grog@freebsd.org>
Cc:        FreeBSD Architecture Mailing List <arch@freebsd.org>
Subject:   Re: Header files with enums instead of defines?
Message-ID:  <20041222090855.GO79646@cirb503493.alcatel.com.au>
In-Reply-To: <20041222010143.GS53357@wantadilla.lemis.com>
References:  <20041222010143.GS53357@wantadilla.lemis.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 2004-Dec-22 11:31:43 +1030, Greg 'groggy' Lehey wrote:
>Has anybody thought about replacing #defines with enums in header
>files?  It would make debugging a whole lot easier.  Foe example, I'm
>currently looking at a debug printout which contains:
>
>  xerrno = 17, 
...
>  xerrno = EEXIST, 

K&R2 states that errno is an "integer expression" and that the error
values are "macros".  I suspect POSIX and newer C standards say something
similar.  Also, the enum value name replacement would only occur if xerrno
was of the appropriate enum type - which would make the code non-portable.

An alternative suggestion for you: Write a gdb macro which takes an
int and prints it as an errno.  Something like a shorthand version of:
  print (enum { EPERM=1, ENOENT=2, ..., EILSEQ=86})xerrno
should work.

You would probably write a [insert scripting language of choice] script
to convert <errno.h> into the appropriate gdb macro.

-- 
Peter Jeremy



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