Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Effective uses of c `goto' statement
Date: Sun, 06 Dec 2020 05:03:00 -0800
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <86ft4jkry3.fsf@linuxsc.com>
References: <87czzszjhs.fsf@fedora.osfans.org> <20201202120809.633@kylheku.com> <86sg8kkyjb.fsf@linuxsc.com> <_CPyH.64249$7D7.63135@fx03.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="048215ee9820886844dd3aade67dded3"; logging-data="3192"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196l0EQct6L8efzfPQSujlcld1jNUU5ccQ="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:gIhUk4cGQaORx+OVgIco0oHBYZQ= sha1:hz64nyTRdImUrrd5vNMPCkMghoU=
Xref: csiph.com comp.lang.c:156972
Richard Damon writes:
> On 12/5/20 11:28 AM, Tim Rentsch wrote:
>
>> Kaz Kylheku <563-365-8930@kylheku.com> writes:
>>
>> [...]
>>
>>> Finite automata re easily implemented without goto, but only goto
>>> offers the most efficient possible representation with the fewest
>>> state variables (possibly with no state variable at all).
>>
>> Unless you can offer some sort of argument supporting this
>> assertion, I'm inclined to believe it is not the case.
>
> Well, you can build the Finite automata where the state you are in
> is the last label you did a 'goto' to (with an optimization that if
> it is the next lable, the goto can be implied). That basically
> eliminates the state variable (maybe some state works better in a
> state variable if you have a series of states that are similar and
> just use a counter).
Yes, I understood that already.
> The non-goto method is typically a switch statement based on the
> state variable, all in a while loop. There each state changes the
> variable and breaks from the switch, and then loops in the while to
> go to the next state.
A common way to implement a state machine is with a switch()
inside a loop of some sort (e.g., for() or while()). I got that
already also.
My question is about other possibilities that do not use goto
but also do not use state variables.