svn commit: trunk/busybox/util-linux

Denis Vlasenko vda.linux at googlemail.com
Tue Sep 19 13:51:29 UTC 2006


On Tuesday 19 September 2006 15:18, Bernhard Fischer wrote:
> On Mon, Sep 18, 2006 at 10:53:08AM -0400, Rob Landley wrote:
> >On Sunday 17 September 2006 11:51 am, vda at busybox.net wrote:
> >> -#define useMtab 0
> >> -#define fakeIt 0
> >> +enum {
> >> +	useMtab = 0,
> >> +	fakeIt = 0,
> >> +};
> >
> >Ok, your argument a moment ago in favor of using enum was scoping rules, and 
> >here you're making a global enum.
> >
> >Anybody else see an inconsistency here?
> 
> I don't like these enums. IMHO they are not readable and -- compared to
> defines -- don't come with any advantage whatsoever.

Okay, let's say you do

#define linenumber 0

What will happen if somebody, somewhere in the jungle of included
header files, already used "linenumber" as a name for something?

With enum, you'll get understandable error message.

With #define, you get no error at the #define site.
You get weird errors somewhere after that.
Say, putchar(), which is usually a macro, will expand to
....; linenumber = 0; .... and you will get "invalid lvalue
in assignment". Not very easy to figure out.

If putchar will expand to ....; something = linenuber;....,
you get NO ERROR. You get nasty bug.

Yes, it is not very likely. libc people will go to great lengths
to prevent this by picking silly names
___glibc_linenumber_you_will_die_if_you_touch_me___
EXACTLY because there were such incidents in the past.

In other words: C scope rules and typechecking are a Good Thing.
We should use them, because they are designed to save us from
common mistakes.

> PS: Not sure if you saw that, but we have a bunch of build-errors in
> current trunk.
> See http://busybox.net/lists/busybox/2006-September/024495.html

Nifty script.... getty.c wants <syslog.h>... done.

"error: parameter name omitted" is gcc's idiotic desire to have
all function parameters named, even those which are unused
(so that it can happily complain "parameter foo is unused").

> Users are starting to put them into the bug-collector as they come
> across them, the url above points most of them out early, fwiw.
--
vda



More information about the busybox mailing list