Re: Use enum to declare errno values

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

 



On Fri, 2 Dec 2005, Bill Davidsen wrote:

> Coywolf Qi Hunt wrote:
> >
> > That is a bad bad style. It should be `#define FOO 123' if you have to
> > write it.
> >
> > It's also hard to see what the confusing bar is "if you are looking at
> > file.c alone".
> >
> > enum is worse than typdef.  Don't you see why we should use `struct
> > task_struct', rather than `task_t'?
> >
> > Introducing enum alone can't solve the problems from bad macro usage
> > habits. Actually, it's not anything wrong with macros, it's
> > programers' bad coding style.
>
> Using enum doesn't *solve* problems, it does *allow* type checking, and
> *prevent* namespace pollution. Use of typedef allows future changes, if
> you use "struct XXX" you're stuck with it.

You're not stuck with anything onerous in this case. Namely,

If you have "enum XXX" and you want to go to "enum YYY", then...
	sed 's/enum XXX/enum YYY/g'
If you have "struct XXX" and you want to go to "struct YYY", then...
	sed 's/struct XXX/struct YYY/g'
If you have "enum XXX" and you want to go to "struct YYY", then...
This is a big change, and should be done with care anyway. If struct YYY
happens to be large, then suddenly you can get all sorts of nifty stack
overflows.

In general, code that does not typedef enums and structs unless
absolutely necessary is easier to work with for these reasons:
1) The type of the variable is very obvious from its 'name', without the
uglyness that is Hungarian notation.
2) You don't need to include definition (such as from a header file)
just to declare a pointer to the type. Cuts down on #include clutter.
3) The enum namespace is separate from the struct namespace, which is
separate from other namespaces. Less naming collisions.

YMMV; not an invitation to start a coding style religious war

> --
> bill davidsen <[email protected]>
>    CTO TMR Associates, Inc
>    Doing interesting things with small computers since 1979
> -

-Vadim Lobanov
-
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