Header files with enums instead of defines?

Peter Jeremy PeterJeremy at optushome.com.au
Wed Dec 22 01:08:58 PST 2004


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


More information about the freebsd-arch mailing list