lkml.org 
[lkml]   [2005]   [Dec]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Use enum to declare errno values
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 <davidsen@tmr.com>
> 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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-12-02 18:01    [W:0.115 / U:0.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site