Re: Header files with enums instead of defines?
From: Garance A Drosihn (drosih_at_rpi.edu)
Date: 12/22/04
- Previous message: Greg 'groggy' Lehey: "Re: Header files with enums instead of defines?"
- In reply to: Greg 'groggy' Lehey: "Header files with enums instead of defines?"
- Next in thread: Peter Jeremy: "Re: Header files with enums instead of defines?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 21 Dec 2004 21:06:32 -0500 To: "Greg 'groggy' Lehey" <grog@freebsd.org>, FreeBSD Architecture Mailing List <arch@freebsd.org>
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 _______________________________________________ freebsd-arch@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-arch To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
- Previous message: Greg 'groggy' Lehey: "Re: Header files with enums instead of defines?"
- In reply to: Greg 'groggy' Lehey: "Header files with enums instead of defines?"
- Next in thread: Peter Jeremy: "Re: Header files with enums instead of defines?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|