Re: Use enum to declare errno values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm going to regret jumping in on this.

On Sat, 2005-12-03 at 01:07 +0800, Coywolf Qi Hunt wrote:
> 2005/12/3, Bill Davidsen <[email protected]>:
> > Coywolf Qi Hunt wrote:
> >
> > > This is a reason why enums are worse than #defines.
> > >
> > > Unlike in other languages, C enum is not much useful in practices.
> >
> > Actually they are highly useful if you know how to use them. They allow
> > type checking, have auto increment, and are part of the language instead
> >   of a feature of the preprocessor.
> 
> Yes, I know type checking and auto increment. But they are not
> worthwhile, at least not for serious C programming. No, I don't know
> how to use them comfortably.

Hmm, I like to use a lot of both enums and macros (defines).  I use
defines mostly for general constants and emums for enumerations.
Although it can be argued that errno should be enums, I would prefer
them as macros.  Especially since they then can be used in asm. (.S
files).

I seldom use enums for kernel programming though.  I use it just to
define a list of numbers where I don't care what their value is (usually
for transition states).  I use defines when I do.  Because errno does
depend on the value (for glibc to figure them out too) then I think
defines are better.

But in user space programming I use enums more often than defines,
because gdb can convert the number into a name.  So instead of seeing
x=0x1234 I see x=FOO.

-- Steve



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux