<div dir="ltr"><div>>> When programming for yourself, anything goes to get to the result as quick and painless as possible for me.</div><div><br></div><div>Boy do I gotta disagree - I even wrote a chapter in my book on this.<br><br></div><div>You always need to program for maintenance, even if you're the only one that will set eyes on it.  I can't recount how many times programmers regretted not using standard practices and couldn't figure out code they had written just 6 months earlier and now have to waste time reengineering it when they just wanted to make a minor change.</div><div><br></div><div>That said, by using a single function call for each case of a switch statement, if that function is used only once, the compiler will optimize it for you into inline functions and likely a goto structure anyway.  Do not try to out optimize an optimizer that has had years of work go into it.  The fact is that it is far too easy to screw up that goto structure by trying to roll it out yourself -- I've been paid to fix other people's mistakes in this.  The whole goal here is to workaround a bug in the interpreter of the Arduino IDE that filters and macros code to be sent through a compiler.<br><br></div><div>Better yet, jump on the open source Arduino IDE project and help fix this bug for the whole world to use!</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 1, 2020 at 5:35 PM Pete Soper via TriEmbed <<a href="mailto:triembed@triembed.org">triembed@triembed.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <p>Dikstra's 1973 proposal of the new language statement was about
      the time I was first using Fortran. In retrospect, the extra
      (accidental) genius of Dijkstra is that he conjured it just one
      year after the release of the Signetics write only memory. The
      Signetics device would have been an ideal destination for the
      results of programs heavily depending on the come from statement.</p>
    <p>-Pete <br>
    </p>
    <div>On 7/1/20 10:45 AM, Rick DeNatale via
      TriEmbed wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div id="gmail-m_4920758902892368380edo-message">How many of you are old enough to remember
        FORTRANs computed go to, and its evil twin the computed come
        from. <a href="https://web.archive.org/web/20180716171336/http://www.fortran.com/fortran/come_from.html" style="letter-spacing:0.1px;text-align:inherit" target="_blank">https://web.archive.org/web/20180716171336/http://www.fortran.com/fortran/come_from.html</a></div>
      <div id="gmail-m_4920758902892368380edo-original">
        <div><br>
          <br>
          <blockquote type="cite" style="margin:1ex 0px 0px;height:min-content;border-left:1px solid rgb(204,204,204);padding-left:0.5ex">
            <div>On Jul 1, 2020 at 9:13 AM, <<a href="mailto:triembed@triembed.org" target="_blank">Scott Hall via TriEmbed</a>>
              wrote:<br>
              <br>
            </div>
            <div>
              <div dir="ltr">
                <div>NO NO, DON'T USE GOTO !</div>
                <div><br>
                </div>
                <div>Seriously though, this has been a behaviour of the
                  Arduino compiler compilation for a while -- its even
                  mentioned in some Arduino books.  The workaround is to
                  have a single function called for each case label and
                  to put the statements desired with the function.  This
                  gets optimized to a jump table anyway, so its just a
                  matter of doing this in practice.<br>
                </div>
              </div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">On Wed, Jul 1, 2020 at
                  12:34 AM Jon Wolfe via TriEmbed <<a href="mailto:triembed@triembed.org" target="_blank">triembed@triembed.org</a>>
                  wrote:<br>
                </div>
                <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
                  <div lang="EN-US">
                    <div>
                      <p class="MsoNormal">Yep, GCC has a ton of
                        extensions to C and C++, though they obviously
                        need careful consideration when using, if it’s
                        work the downside of making the code less
                        portable. </p>
                      <p class="MsoNormal"> </p>
                      <p class="MsoNormal"><a href="https://gcc.gnu.org/onlinedocs/gcc-5.2.0/gcc/C-Extensions.html" target="_blank">https://gcc.gnu.org/onlinedocs/gcc-5.2.0/gcc/C-Extensions.html</a></p>
                      <p class="MsoNormal"> </p>
                      <p class="MsoNormal">One of my favorites is local
                        functions. </p>
                      <p class="MsoNormal"> </p>
                      <p class="MsoNormal"> </p>
                      <p class="MsoNormal"> </p>
                      <div style="border-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;padding:3pt 0in 0in">
                        <p class="MsoNormal" style="border:medium none;padding:0in"><b>From: </b><a href="mailto:ncgadgetry@gmail.com" target="_blank">Rodney
                            Radford</a><br>
                          <b>Sent: </b>Tuesday, June 30, 2020 9:04 PM<br>
                          <b>To: </b><a href="mailto:jonjwolfe@anibit.com" target="_blank">Jon
                            Wolfe</a><br>
                          <b>Cc: </b><a href="mailto:triembed@undecidedgames.net" target="_blank">Brian</a>;
                          <a href="mailto:triembed@triembed.org" target="_blank">Triangle
                            Embedded Computing Discussion</a><br>
                          <b>Subject: </b>Re: [TriEmbed] Hacking a fake
                          vintage radio (with Arduino + Pi 0)</p>
                      </div>
                      <p class="MsoNormal"> </p>
                    </div>
                  </div>
                  <div dir="ltr">
                    <div dir="ltr">
                      <div>I had never heard of the GCC label variable,
                        so I had to google it... wow, I learned
                        something new tonight!</div>
                      <div><br>
                      </div>
                      <div><a href="https://stackoverflow.com/questions/1777990/is-it-possible-to-store-the-address-of-a-label-in-a-variable-and-use-goto-to-jum" target="_blank">https://stackoverflow.com/questions/1777990/is-it-possible-to-store-the-address-of-a-label-in-a-variable-and-use-goto-to-jum</a><br>
                        <br>
                      </div>
                    </div>
                  </div>
                  <br>
                  <div class="gmail_quote">
                    <div class="gmail_attr" dir="ltr">On Tue, Jun 30,
                      2020 at 8:57 PM Jon Wolfe via TriEmbed <<a href="mailto:triembed@triembed.org" target="_blank">triembed@triembed.org</a>>
                      wrote:<br>
                    </div>
                    <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left:1px solid rgb(204,204,204)">
                      <div lang="EN-US">
                        <div>
                          <p class="MsoNormal"> </p>
                          <p class="MsoNormal">There is a trick you can
                            use with gcc that is a non-standard C
                            construct where you can use ‘goto’ and give
                            it a variable containing the address of a
                            label. You then create an array of label
                            address and you can then dynamically index
                            that array to jump to various locations. 
                            I’ve seen it used as an optimization
                            technique, and you can also have more
                            control over the program flow, though it is
                            using the infamous keyword, Essentially
                            though it end up looking pretty much like a
                            switch-case. </p>
                          <p class="MsoNormal"> </p>
                          <p class="MsoNormal">That is really odd about
                            that gcc bug.  It’s not like I’ve never seen
                            them, but 99.9% of the time when I thought I
                            had found a compiler bug in C/C++, it turns
                            out to be something else. (hafl the time one
                            of those things that disappears with a
                            “clean/rebuild all”)  I remember the Arduino
                            /AVR/gcc linker used to have a bug related
                            to 8-bit AVR chips that had more than 64KB
                            of flash memory, such as the ATMega 1284.
                            Those chips address by 16 bit words not
                            bytes, so 128kb of flash is accessible
                            without trick likes far pointers, but the
                            linker would mess up the address
                            calculations sometimes I think for interrupt
                            handlers or functions called by interrupt
                            handlers that crossed the 64kb boundary. </p>
                          <p class="MsoNormal"> </p>
                          <p class="MsoNormal"> </p>
                          <div style="border-width:1pt medium medium;border-style:solid none none;border-color:rgb(225,225,225) currentcolor currentcolor;padding:3pt 0in 0in">
                            <p class="MsoNormal" style="padding:0in;border:medium none"><b>From:
                              </b><a href="mailto:triembed@triembed.org" target="_blank">Huan
                                Truong via TriEmbed</a><br>
                              <b>Sent: </b>Tuesday, June 30, 2020 12:48
                              PM<br>
                              <b>To: </b><a href="mailto:triembed@undecidedgames.net" target="_blank">Brian</a><br>
                              <b>Cc: </b><a href="mailto:triembed@triembed.org" target="_blank">Triangle
                                Embedded Computing Discussion</a><br>
                              <b>Subject: </b>Re: [TriEmbed] Hacking a
                              fake vintage radio (with Arduino + Pi 0)</p>
                          </div>
                          <p class="MsoNormal"> </p>
                        </div>
                      </div>
                      Oh yeah, that explains my issue. I definitely ran
                      into that issue<br>
                      where I have checked and had no reason to believe
                      I was doing<br>
                      something wrong, yet, when I evacuated each switch
                      to a function, the<br>
                      switch worked correctly. But neither scoping with
                      an anonymous scope<br>
                      nor renaming the variables work.<br>
                      <br>
                      The reason I used the switch was that I read on
                      stackoverflow at one<br>
                      point and someone said that we should use switches
                      instead of elseifs<br>
                      when we have a lot of cases. Then, using switches,
                      the compiler will<br>
                      be able to (at some point) create a lookup table
                      for you so it's<br>
                      faster. I doubt that was what happening at least
                      on the Arduino case.<br>
                      You'll need a giant lookup table which the uCs
                      don't have memory for.<br>
                      I suspect that in a lot of cases, using switches
                      is probably just as<br>
                      slow as using elseifs. Now as I see that it is so
                      buggy, I probably<br>
                      will not use switches, at least on Arduino.<br>
                      <br>
                      Cheers,<br>
                      - Huan.<br>
                      <br>
                      On Tue, Jun 30, 2020 at 9:23 AM Brian via TriEmbed<br>
                      <<a href="mailto:triembed@triembed.org" target="_blank">triembed@triembed.org</a>>
                      wrote:<br>
                      ><br>
                      > Side note:<br>
                      ><br>
                      > The arduino compiler has bugs in how it
                      handles switch statements. I've<br>
                      > run into situations lately where the order of
                      the case statements matter<br>
                      > (which it never should); cases are completely
                      ignored, etc.<br>
                      ><br>
                      > I believe it may be tied to the use of local
                      scoping within a case, e.g.:<br>
                      ><br>
                      > switch(thing) {<br>
                      > case 1:<br>
                      > {<br>
                      > // stuff with case-local scope<br>
                      > }<br>
                      > break;<br>
                      > }<br>
                      ><br>
                      > Syntactically- and semantically-correct code
                      has proven to generate<br>
                      > incorrect runtime results.<br>
                      ><br>
                      > I haven't had time/motivation to submit a bug
                      report, but I should do<br>
                      > that. At any rate, a potential workaround is
                      to reorder your cases.<br>
                      ><br>
                      > -B<br>
                      ><br>
                      > On 6/24/20 9:51 PM, Huan Truong via TriEmbed
                      wrote:<br>
                      > > Thanks Pete!<br>
                      > ><br>
                      > > I feel like there was something really
                      mysterious about the switch statement. Even if I
                      pasted the whole blocks of code of each function I
                      would have called to the {} inside a case, the
                      code still wouldn’t work. That baffled me by a
                      mile.<br>
                      > ><br>
                      > > But yeah, I spent way too much time on
                      the project that I’m comfortable with the idea of
                      not understanding some of it now. The watchdog
                      timer code was baffling too.<br>
                      > ><br>
                      > > Please excuse my typos, sent from phone.<br>
                      > ><br>
                      > > On Jun 24, 2020, at 10:14 AM, Pete Soper
                      via TriEmbed <<a href="mailto:triembed@triembed.org" target="_blank">triembed@triembed.org</a>>
                      wrote:<br>
                      > ><br>
                      > > What a beautifully presented adventure.
                      Loved reading it. And when you say a problem
                      "could be bad" you make your point. :-) (meant as
                      a "find Waldo" exercise for alert readers)<br>
                      > ><br>
                      > > Hadn't heard of "kev" or any other
                      Arduino emulator for that matter. That aspect was
                      interesting too.<br>
                      > ><br>
                      > > The other issue with redeclaration of
                      the vars local to the switch statement is that
                      they literally don't exist outside it, so
                      communicating their values outside the block would
                      be difficult. :-) In general, every {} defines a
                      local scope in C/C++ and you can declare variables
                      inside that scope but they cease to be defined
                      outside the scope. The scope outside any {} (aka
                      "global") or vars declared "static" can avoid this
                      issue but not the redefine issue.<br>
                      > ><br>
                      > > Thanks for sharing this!<br>
                      > ><br>
                      > > Pete<br>
                      > ><br>
                      > ><br>
                      > >> On 6/24/20 12:43 PM, Huan Truong via
                      TriEmbed wrote:<br>
                      > >> This has taken me way more time than
                      I thought, but finishing this<br>
                      > >> retrofit is a big achievement for
                      me. It's really silly and serves<br>
                      > >> exactly no purpose other than RE'ing
                      something no one cares about. So<br>
                      > >> I just want to share for some shits
                      and giggles.<br>
                      > >><br>
                      > >> <a href="http://www.tnhh.net/posts/adventures-hacking-fake-vivitar-vintage-radio.html" target="_blank">http://www.tnhh.net/posts/adventures-hacking-fake-vivitar-vintage-radio.html</a><br>
                      > >><br>
                      > >><br>
                      > >><br>
                      > >><br>
                      > >><br>
                      > ><br>
                      > >
                      _______________________________________________<br>
                      > > Triangle, NC Embedded Computing mailing
                      list<br>
                      > ><br>
                      > > To post message: <a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
                      > > List info: <a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
                      > > TriEmbed web site: <a href="http://TriEmbed.org" target="_blank">http://TriEmbed.org</a><br>
                      > > To unsubscribe, click link and send a
                      blank message: mailto:<a href="mailto:unsubscribe-TriEmbed@bitser.net" target="_blank">unsubscribe-TriEmbed@bitser.net</a>?subject=unsubscribe<br>
                      > ><br>
                      > ><br>
                      > >
                      _______________________________________________<br>
                      > > Triangle, NC Embedded Computing mailing
                      list<br>
                      > ><br>
                      > > To post message: <a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
                      > > List info: <a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
                      > > TriEmbed web site: <a href="http://TriEmbed.org" target="_blank">http://TriEmbed.org</a><br>
                      > > To unsubscribe, click link and send a
                      blank message: mailto:<a href="mailto:unsubscribe-TriEmbed@bitser.net" target="_blank">unsubscribe-TriEmbed@bitser.net</a>?subject=unsubscribe<br>
                      > ><br>
                      ><br>
                      ><br>
                      >
                      _______________________________________________<br>
                      > Triangle, NC Embedded Computing mailing list<br>
                      ><br>
                      > To post message: <a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
                      > List info: <a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
                      > TriEmbed web site: <a href="http://TriEmbed.org" target="_blank">http://TriEmbed.org</a><br>
                      > To unsubscribe, click link and send a blank
                      message: mailto:<a href="mailto:unsubscribe-TriEmbed@bitser.net" target="_blank">unsubscribe-TriEmbed@bitser.net</a>?subject=unsubscribe<br>
                      ><br>
                      <br>
                      <br>
                      -- <br>
                      <br>
                      Huan Truong<br>
                      www <a href="http://tnhh.net" target="_blank">tnhh.net</a> / twitter
                      @huant<br>
                      <br>
                      _______________________________________________<br>
                      Triangle, NC Embedded Computing mailing list<br>
                      <br>
                      To post message: <a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
                      List info: <a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
                      TriEmbed web site: <a href="http://TriEmbed.org" target="_blank">http://TriEmbed.org</a><br>
                      To unsubscribe, click link and send a blank
                      message: mailto:<a href="mailto:unsubscribe-TriEmbed@bitser.net" target="_blank">unsubscribe-TriEmbed@bitser.net</a>?subject=unsubscribe<br>
                      <br>
                      _______________________________________________<br>
                      Triangle, NC Embedded Computing mailing list<br>
                      <br>
                      To post message: <a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
                      List info: <a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" rel="noreferrer" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
                      TriEmbed web site: <a href="http://TriEmbed.org" rel="noreferrer" target="_blank">http://TriEmbed.org</a><br>
                      To unsubscribe, click link and send a blank
                      message: mailto:<a href="mailto:unsubscribe-TriEmbed@bitser.net" target="_blank">unsubscribe-TriEmbed@bitser.net</a>?subject=unsubscribe<br>
                      <br>
                    </blockquote>
                  </div>
                  _______________________________________________<br>
                  Triangle, NC Embedded Computing mailing list<br>
                  <br>
                  To post message: <a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
                  List info: <a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" rel="noreferrer" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
                  TriEmbed web site: <a href="http://TriEmbed.org" rel="noreferrer" target="_blank">http://TriEmbed.org</a><br>
                  To unsubscribe, click link and send a blank message:
                  mailto:<a href="mailto:unsubscribe-TriEmbed@bitser.net" target="_blank">unsubscribe-TriEmbed@bitser.net</a>?subject=unsubscribe<br>
                  <br>
                </blockquote>
              </div>
              <br clear="all">
              <br>
              -- <br>
              <div dir="ltr">
                <div dir="ltr">
                  <div>
                    <div dir="ltr">
                      <div>
                        <div dir="ltr">
                          <div>Scott G. Hall<br>
                            Raleigh, NC, USA<br>
                            <a href="mailto:scottghall1@gmail.com" target="_blank">scottghall1@gmail.com</a></div>
                          <i>Although kindness is rarely a job, no
                            matter what you do it's always an option.</i><br>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              _______________________________________________
              Triangle, NC Embedded Computing mailing list
              To post message: <a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a>
              List info:
              <a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a>
              TriEmbed web site: <a href="http://TriEmbed.org" target="_blank">http://TriEmbed.org</a>
              To unsubscribe, click link and send a blank message:
              <a href="mailto:unsubscribe-TriEmbed@bitser.net?subject=unsubscribe" target="_blank">mailto:unsubscribe-TriEmbed@bitser.net?subject=unsubscribe</a>
            </div>
          </blockquote>
        </div>
      </div>
      <br>
      <fieldset></fieldset>
      <pre>_______________________________________________
Triangle, NC Embedded Computing mailing list

To post message: <a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a>
List info: <a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a>
TriEmbed web site: <a href="http://TriEmbed.org" target="_blank">http://TriEmbed.org</a>
To unsubscribe, click link and send a blank message: <a href="mailto:unsubscribe-TriEmbed@bitser.net?subject=unsubscribe" target="_blank">mailto:unsubscribe-TriEmbed@bitser.net?subject=unsubscribe</a>

</pre>
    </blockquote>
  </div>

_______________________________________________<br>
Triangle, NC Embedded Computing mailing list<br>
<br>
To post message: <a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
List info: <a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" rel="noreferrer" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
TriEmbed web site: <a href="http://TriEmbed.org" rel="noreferrer" target="_blank">http://TriEmbed.org</a><br>
To unsubscribe, click link and send a blank message: mailto:<a href="mailto:unsubscribe-TriEmbed@bitser.net" target="_blank">unsubscribe-TriEmbed@bitser.net</a>?subject=unsubscribe<br>
<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>Scott G. Hall<br>Raleigh, NC, USA<br><a href="mailto:scottghall1@gmail.com" target="_blank">scottghall1@gmail.com</a></div><i>Although kindness is rarely a job, no matter what you do it's always an option.</i><br></div></div></div></div></div></div>