Re: Header files with enums instead of defines?

From: Garance A Drosihn (drosih_at_rpi.edu)
Date: 12/22/04

  • Next message: Jun Su: "Re: Propose for Several Dump types"
    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"
    

  • Next message: Jun Su: "Re: Propose for Several Dump types"

    Relevant Pages

    • Re: enum safety
      ... 'Although variables of enum types may be declared, compilers need not ... In this case, c is of type char*, purple is of type enum ... creates a series of constants (which, oddly enough, are of type int, ...
      (comp.lang.c)
    • Re: resolving a warning error
      ... >This works on several systems and compilers, but fails on aix xlc. ... Not if you invoke them in conforming mode: ... >warning messages and without declaring the enum? ...
      (comp.lang.c)
    • Re: Why no/limited checking on enum values ?
      ... but compilers are always allowed to ... >An enum type is a symbolic name for an int. ... C89 standard appears to me to allow even "enum C" to use an unsigned ... standards do allow it, would not survive in the marketplace....) ...
      (comp.lang.c)
    • Re: which object orient language is most suitable for embedded programming?
      ... typedef enum, for example, produces a range of values which are of type int. ... The variable takes on the type int. ... Some compilers have switches to select 8 or 16 bit enums, but it's not a general solution. ...
      (comp.arch.embedded)
    • Re: enum size in WinCE compiler
      ... As far as I can tell, no, there's no way to change the size of the enum. ... unsigned char packetData; ... Is there anyway to alter the size of enum data types with WinCE ... Several compilers like GCC, ...
      (microsoft.public.windowsce.embedded)