Pages: [1] 2   Go Down
Author Topic: GOTO is back  (Read 2256 times)
0 Members and 1 Guest are viewing this topic.
nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8490
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

At last we can use GOTO again without being vilified smiley

The new MISRA standard now allows it's use (with caveats), I haven't seen the standard yet but here's a excerpt from an article on the Electronic Design site (http://electronicdesign.com/dev-tools/misra-c2012-plenty-good-reasons-change?NL=ED-07&Issue=ED-07_20130226_ED-07_678&YM_RID=rob@robgray.com&YM_MID=1375780&sfvc4enews=42)

Quote
Not All Goto Statements Patch Up Wooly Thinking!

All too often, goto statements are used to patch up wooly thinking or an ill-defined algorithm. However, there are situations where the use of the goto statement is justified. For example, if there is an emergency situation in a process-control application, is it really better to set a flag and check it later in the algorithm than to take a direct route via a goto?  The “goto statement should not be used” rule is now advisory rather than required, and an additional two rules narrow down the circumstances under which it is acceptable:

    The goto statement shall jump to a label declared later in the same function.
    Any label referenced by a goto statement shall be declared in the same block, or in any block enclosing the goto statement.

So all us wooly thinkers are off the hook now smiley

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Tasmania - Australia
Offline Offline
Sr. Member
****
Karma: 14
Posts: 307
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nooooooooooo, yee shall not pass goto, for if thou do'eth thou surely be cast into thee depths of eternity, lost and abandoned it time, never to return.
Logged


Global Moderator
Online Online
Brattain Member
*****
Karma: 480
Posts: 18720
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
    The goto statement shall jump to a label declared later in the same function.

So, you can't use it for loops.
Logged


nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8490
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, it looks like you can only jump forward.

Rockwallaby, I'll have what you're having smiley

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 216
Posts: 13663
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

in case of an emergency you can use goto but you must not expect the system in a defined state thereafter. Even a graceful degradation is doubtful at best.

If you detect a real emergency (the "Houston we got a problem" kind) why not call the emergencyHandler() ?
And return afterwards and continue?

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 91
Posts: 4217
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If you detect a real emergency...

... who you gonna call? ghostBusters()

But if you have a huuuuge @#$%up, call Todd() ....


* calltodd.jpg (14.53 KB, 265x190 - viewed 57 times.)
Logged

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 216
Posts: 13663
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

LOL !
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Show Your Work
Offline Offline
Edison Member
*
Karma: 14
Posts: 1089
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

GOTO "never left the building" for assembly language programmers.
Logged

I have only come here seeking knowledge. Things they would not teach me of in college.

Global Moderator
Online Online
Brattain Member
*****
Karma: 480
Posts: 18720
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you use GOTO, I think you are going to end up calling Todd (see graphic above).
Logged


Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 520
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Will spaghetti be served again?  smiley-eek-blue
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8490
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
call Todd
I saw that sign recently on one of those "funny photos" sites, under the heading "Meanwhile in Aus" or some such. It's a classic.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Sr. Member
****
Karma: 9
Posts: 296
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

GOTO "never left the building" for assembly language programmers.

+1. Goto, Jump, Branch...
Logged

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 91
Posts: 4217
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I saw that sign recently on one of those "funny photos" sites, under the heading "Meanwhile in Aus" or some such.

Well you guys do have a certain "way" with words, let's face it...
Logged

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 40
Posts: 5570
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I involved myself in this conversation way-back-when on the electro-tech forum, regarding state machines:

http://www.electro-tech-online.com/general-electronics-chat/113718-state-machine-mcu.html

In it, me and another user (MikeMI) have a discussion regarding state machines and whether using IF-THEN logic and GOTOs for such implementations (vs a switch-case construct) is better, worse, or...?

Anyhow - he posted an image of an implementation of such a state machine:

http://www.electro-tech-online.com/attachments/general-electronics-chat/48665d1291323569-state-machine-mcu-elevator.png

(you'll need a login to see it) - or check it out here, rehosted: http://i.imgur.com/JkND1Av.png

Anyhow - I found that example of using IF-THEN logic and GOTO to implement such logic to be very interesting; it wasn't difficult to follow, and made me appreciate GOTO a bit more (I grew up on Microsoft BASIC on a TRS-80 Color Computer - GOTO was in my blood for a long time, until it was excised during my first professional software development gig).

I now think of it as one of those tools that one should be aware of, but should only use when the situation absolutely warrants it - breaking out of deeply nested logic is one potential area (provided you don't break a stack or something); though I would perhaps do some investigation into that logic to see if maybe there is some way to make it more workable without requiring such a sledgehammer measure.

...and a second potential situation would be this example of a state machine.

I have also seen an instance (when I worked at a place that used a variant of COBOL called DB/C) where GOTO was used to jump out of (or into? it's been so long now) an error "trap" routine; but the developers there who worked in that system (I was only peripherally involved) made it explicit that such use was the -only- place that GOTO was allowed in the software they developed, and no where else.
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 91
Posts: 4217
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I now think of it as one of those tools that one should be aware of, but should only use when the situation absolutely warrants it

Like using water-pump-pliers to undo a nut....
Logged

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Pages: [1] 2   Go Up
Jump to: