Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Ethereal-dev: RE: [Ethereal-dev] [Patch] iostat win32 build

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "Esh, Andrew" <AEsh@xxxxxxxxxxx>
Date: Mon, 2 Dec 2002 14:20:33 -0600
Title: RE: [Ethereal-dev] [Patch] iostat win32 build

I'm in favor of the breaks.

Whenever I write a case statement with an empty body, I put a "break;" as the body. This prevents the introduction of a bug if someone were to later add another case below mine. Doing so would cause my case to execute the body of the new case statement. The next person to work on the code might not notice that the case above it is "bottomless" and will fall through.

BTW: In the syntax below, it is also legal to have multiple cases stacked above a single statement, so "case {constant-_expression_} :" is legal, if it is followed by another case. I'm not sure if that's standard C, but it's so common it ought to be.

-----Original Message-----
From: Guy Harris [mailto:guy@xxxxxxxxxx]
Sent: Monday, December 02, 2002 1:52 PM
To: Jason House
Cc: Ethereal Development
Subject: Re: [Ethereal-dev] [Patch] iostat win32 build


On Mon, Dec 02, 2002 at 10:30:49AM -0500, Jason House wrote:
> Well, I just tried to build the latest io_stat and found that it didn't
> compile...  I looked at the code and it was fine... but for whatever
> reason, visual studio doesn't like the "default:" followed by "}" with
> nothing in between.

Perhaps it doesn't like it because ANSI X3.159-1989, "American National
Standard for Information Systems -- Programming Language -- C", and
presumably the ISO standard, say, in section 3.6.1 "Labeled Statements":

        Syntax

             {labeled-statement}:

                {identifier} : {statement}
                case {constant-_expression_} : {statement}
                default : {statement}

and nowhere, at least in a quick look, allows {statement} to be empty.

I.e., the oddity isn't that it dislikes it, as it's not valid C; the
oddity that GCC *doesn't* dislike it - it's either a deliberate GCC
extension (although the titles of extensions in the online 2.95.3
manual:

        http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC61

don't show anything that *immediately* suggests that as an extension) or
a consequence of the way GCC's parser was written.

> I simply added "break;" and it compiles fine now.

Checked in.

> Index: io_stat.c
> ===================================================================
> RCS file: /cvsroot/ethereal/gtk/io_stat.c,v
> retrieving revision 1.8
> diff -r1.8 io_stat.c
> 430a431
> >                             break;
> 458a460
> >                             break;
> 461a464
> >                     break;
> 464a468
> >             break;

You might want to send patches as "diff -c" or "diff -u" patches in the
future - that one happened to apply because the current version of
"io_stat.c" is the one against which you diffed your version, but
context or unified diffs are more robust in the face of others changing
the file you're patching.
_______________________________________________
Ethereal-dev mailing list
Ethereal-dev@xxxxxxxxxxxx
http://www.ethereal.com/mailman/listinfo/ethereal-dev