bug-bison
[Top][All Lists]
Advanced

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

Re: default statement notice


From: Hans Aberg
Subject: Re: default statement notice
Date: Tue, 18 Jan 2005 19:52:07 +0100
User-agent: Microsoft-Outlook-Express-Macintosh-Edition/5.0.6

On 2005/01/18 09:26, Paul Eggert at address@hidden wrote:

> address@hidden writes:
> 
>> Thanks for the Hans Aberg notice about the `default:' statement.
>> Looks like its safe for c but possibly not for all c++ compilers.
> 
> Sorry, but I couldn't really follow what he wrote.  My guess is that
> he was writing about his own C++ template file, which is a different
> animal.

It is part about some changes I think was made in the past, some of them I
have in my own C++ skeleton file, but also about changes about future C++
developments. These issues have been discussed in the Bison lists. But
because I do use my own C++ skeleton file, I do not recall the details. If
Bison in the future gets the tweaks I need in order to implement my C++
skeleton file, then I can be more specific. :-)

> The C++ code that is generated by Bison 2.0 does not use "default:"
> here, and his remarks about Bison using "default:" to implement $$ =
> $1 do not seem to apply to the templates shipped with Bison 2.0.

I have a vague memory that the default action was moved into the switch
statement in some earlier C-skeleton file. But I could misremember.

> Perhaps in some later version of the template we'll use "default:"
> along the lines that he suggests; at that point, of course we'll have
> to remove the "default:break;" that I just added.  But in the meantime
> I don't see how the "default:break;" could hurt, regardless of whether
> we're using C or C++.

Right now, under C++, one can only use a typed parser by using %union, and
for C/C++ unions, $$ = $1 implies $<type_name>$ = $<type_name>$. So as long
as that is the case, there will be no problems. Before then, if the default
action is without (i.e., before) the switch statement, then there are two
ways to implement it: First, after the default action has been executed, one
makes a jump past the switch statement, in which case the default action
will never be executed. Second, if one does not make that jump, then the
switch statement, then one must not end up in any of the other actions. All
those case numbers that can occur except possibly the default action ones
then are explicitly written out, so it embarks down to how the compilers
implements a switch statement without a default when the switch number is
not in any of the written case numbers. Many compilers will probably
generate some kind of diagnostics. I think there the safest and most prudent
C/C++ thing is to always have a default case in the switch statement. So if
the switch statement does not have a default case, then it should probably
have a "default:break;" just in order to avoid compiler diagnostics.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]