nr Bundaberg, Australia
Offline
Tesla Member
Karma: 71
Posts: 6809
Scattered showers my arse -- Noah, 2348BC.
|
 |
« on: February 26, 2013, 08:00:42 pm » |
At last we can use GOTO again without being vilified  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) 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  ______ Rob
|
|
|
|
|
Logged
|
|
|
|
|
Tasmania - Australia
Offline
Sr. Member
Karma: 7
Posts: 251
|
 |
« Reply #1 on: February 27, 2013, 03:35:50 am » |
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
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #2 on: February 27, 2013, 03:43:40 am » |
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
Tesla Member
Karma: 71
Posts: 6809
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #3 on: February 27, 2013, 11:09:38 am » |
Yeah, it looks like you can only jump forward. Rockwallaby, I'll have what you're having  ______ Rob
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 87
Posts: 9371
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #4 on: February 27, 2013, 02:05:23 pm » |
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
|
|
|
|
|
Johannesburg UTC+2
Offline
Edison Member
Karma: 34
Posts: 1705
|
 |
« Reply #5 on: February 27, 2013, 02:11:27 pm » |
If you detect a real emergency... ... who you gonna call? ghostBusters() But if you have a huuuuge @#$%up, call Todd() ....
|
|
|
|
|
Logged
|
IT Crowd: Roy... "Have you tried turning it off and on again?" Moss.. "Have you tried forcing an unexpected reboot?"
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 87
Posts: 9371
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #6 on: February 27, 2013, 02:21:55 pm » |
LOL !
|
|
|
|
|
Logged
|
|
|
|
|
Samplefinger
Offline
God Member
Karma: 8
Posts: 818
ALWAYS ASK FOR THREE. One to use. One to lose. One to abuse.
|
 |
« Reply #7 on: February 27, 2013, 03:36:36 pm » |
GOTO "never left the building" for assembly language programmers.
|
|
|
|
|
Logged
|
Latest Sampling Scores: ATXMEGA64A3U-MH x3, ATXMEGA256A3U-MH x3, SST38VF6404-90-5C-EKE x3, SST38VF6402-90-5C-EKE x3, PGA870 x3, THS770006 x3
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #8 on: February 27, 2013, 03:40:07 pm » |
If you use GOTO, I think you are going to end up calling Todd (see graphic above).
|
|
|
|
|
Logged
|
|
|
|
|
Venezuela
Offline
Full Member
Karma: 8
Posts: 228
Ground.......ground........always ground
|
 |
« Reply #9 on: February 27, 2013, 05:30:58 pm » |
Will spaghetti be served again? 
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 71
Posts: 6809
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #10 on: February 27, 2013, 07:43:07 pm » |
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
|
|
|
|
|
Offline
Sr. Member
Karma: 9
Posts: 279
|
 |
« Reply #11 on: February 27, 2013, 08:22:16 pm » |
GOTO "never left the building" for assembly language programmers.
+1. Goto, Jump, Branch...
|
|
|
|
|
Logged
|
|
|
|
|
Johannesburg UTC+2
Offline
Edison Member
Karma: 34
Posts: 1705
|
 |
« Reply #12 on: February 27, 2013, 11:03:59 pm » |
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
|
IT Crowd: Roy... "Have you tried turning it off and on again?" Moss.. "Have you tried forcing an unexpected reboot?"
|
|
|
|
Phoenix, Arizona USA
Offline
Faraday Member
Karma: 27
Posts: 5078
Where's the beer?
|
 |
« Reply #13 on: February 28, 2013, 12:06:03 am » |
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.htmlIn 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.pngAnyhow - 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
|
|
|
|
|
Johannesburg UTC+2
Offline
Edison Member
Karma: 34
Posts: 1705
|
 |
« Reply #14 on: February 28, 2013, 12:11:52 am » |
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
|
IT Crowd: Roy... "Have you tried turning it off and on again?" Moss.. "Have you tried forcing an unexpected reboot?"
|
|
|
|
|