Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Dec 2004 21:06:32 -0500
From:      Garance A Drosihn <drosih@rpi.edu>
To:        "Greg 'groggy' Lehey" <grog@freebsd.org>, FreeBSD Architecture Mailing List <arch@freebsd.org>
Subject:   Re: Header files with enums instead of defines?
Message-ID:  <p06200789bdee83ea0f66@[128.113.24.47]>
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
At 11:31 AM +1030 12/22/04, Greg 'groggy' Lehey wrote:
>
>To find out what that means, I need to go to
>/usr/src/include/sys/errno.h and look for 17.  I find:
>
>#define	EEXIST		17		/* File exists */
>
>If we were to change this to
>
>enum EEXIST = 17;	                /* File exists */
>
>I'd then be able to see:
>
>   xerrno = EEXIST,
>
>That makes debugging a whole lot easier.  About the only down side
>I can see is that you can't #undef an enum.  Is this a big deal?

You also can't #ifdef an enum.

You also can't:
     enum EEXIST = 17;
I'm not a C expert, but you need something more like:
     enum ERRVALS { EEXIST = 17 };
At least that compiles for me.

Some C compilers (irix) will also complain if you assign an
enum-value (such as EEXIST) to a variable which isn't of the same
enum-type (eg: ERRVALS).  So, in those compilers you would have
to define 'xerror' as 'enum ERRVALS xerror', not 'int xerror'.
I think that isn't part of the C standard, but on occassion that
check has found a few bugs for me...

-- 
Garance Alistair Drosehn            =   gad@gilead.netel.rpi.edu
Senior Systems Programmer           or  gad@freebsd.org
Rensselaer Polytechnic Institute    or  drosih@rpi.edu



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