Insufficiently Random

The lonely musings of a loosely connected software developer.

Wednesday, April 26, 2006

That's Legal?!

Today I found this gem on the GIT mailing list:


Timo Hirvonen wrote:
> Linus Torvalds wrote:
>
> > +void verify_filename(const char *prefix, const char *arg)
> > +{
> > + const char *name;
> > + struct stat st;
> > +
> > + if (*arg == '-')
> > + die("bad flag '%s' used after filename", arg);
> > + name = prefix ? prefix_filename(prefix, strlen(prefix), arg) : arg;
> > + if (!lstat(name, &st))
> > + return;
> > + if (errno == ENOENT);
>
> Extra semicolon.


Just what were the authors of C thinking when they decided to allow:


if (errno == ENOENT);


as a legal statement? It clearly has no real purpose as the "then-clause" of the if statement is completely empty.

What's really bad is this language feature is also available in C++, Objective-C, Java, Perl, etc. I'm so glad modern language designers have kept the warts intact.

1 comments :

anon said...

Perl requires a block after if, else, and crew.

Besides, an you're assuming only people write code. Code writes code, too, and sometimes it's easier to let the later compiler optimize out an unnecessary if test than to do all the side-effect analysis yourself. Consider if (c = getchar());. That could be generated for a "don't care" entry in a stream.

Post a Comment