Hot!goto label

Page: 12345.. > >> Showing page 1 of 6
Author
BL
Starting Member
  • Total Posts : 82
  • Reward points : 0
  • Joined: 2011/01/23 10:15:14
  • Location: 0
  • Status: offline
2018/02/05 00:25:21 (permalink)
0

goto label

This works:
MyLabel:
....
....
goto MyLabel;

 
This brings an compiler error:
goto MyLabel;
....
....
MyLabel:


You have to do differently in XC8?
#1

114 Replies Related Threads

    jtemples
    Super Member
    • Total Posts : 10891
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: goto label 2018/02/05 01:10:34 (permalink)
    +1 (1)
    What error?  Post your real code.
    #2
    BL
    Starting Member
    • Total Posts : 82
    • Reward points : 0
    • Joined: 2011/01/23 10:15:14
    • Location: 0
    • Status: offline
    Re: goto label 2018/02/05 01:15:42 (permalink)
    0
    Ah, OK.

    This works:
    goto MyLabel;
    ....
    ....
     
    MyLabel:
    ....
    ....



    #3
    jtemples
    Super Member
    • Total Posts : 10891
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: goto label 2018/02/05 01:20:05 (permalink)
    +1 (1)
    That still isn't real code, but we can guess that your label wasn't followed by a statement.
    #4
    du00000001
    Just Some Member
    • Total Posts : 2075
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: goto label 2018/02/05 01:29:42 (permalink)
    -1 (1)
    @ jtemples
    No - BL needs glasses. (You maybe too.)
    Look at the fist post: he mistook ; for :
     
    See my footnote :)

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #5
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: goto label 2018/02/05 01:47:20 (permalink)
    +2 (2)
    du00000001
    @ jtemples
    No - BL needs glasses. (You maybe too.)
    Look at the fist post: he mistook ; for :
     
    See my footnote :)


    I don't want to ask what a "fist post is" ! ;)
    The colons and semi colons look fine in the first post, maybe there's a fly speck on your screen...
     
    The OP doesn't seem to understand what "post real code" means.
    Do a cut and paste directly from the whole function you are trying to compile.
    Do not key in a fake "example" of what you think you have.

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #6
    1and0
    Access is Denied
    • Total Posts : 8337
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: goto label 2018/02/05 04:40:56 (permalink)
    +2 (2)
    First post you said it does not work, but on Post #3 you said it works.  So, problem solved?
     
    #7
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2645
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: goto label 2018/02/05 06:40:17 (permalink)
    0 (2)
    goto
     
    Really?

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #8
    bblessing
    Super Member
    • Total Posts : 690
    • Reward points : 0
    • Joined: 2008/12/04 06:44:21
    • Location: Cincinnati, OH
    • Status: offline
    Re: goto label 2018/02/05 08:23:41 (permalink)
    +3 (3)
    Gort2015
    goto
     
    Really?


    Actually, yes. I was once very dogmatic about not using goto until I started looking at ways to make my code look cleaner; I totally understand the paradox there: clean code and goto generally don't mix. However, I have found cases where it is actually useful and cuts down on the amount of indentation. If you have cleanup code that needs to be run after multiple conditions in a function before it returns then a goto can be helpful.
     
    The key is keeping the label that goto jumps to confined to the same function as the goto statement itself and only allow the jump to move "forward".
     
    Of course, I don't exclude the possibility that I just write really crappy code :-).
    #9
    jack@kksound
    code tags!
    • Total Posts : 2736
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: goto label 2018/02/05 09:13:29 (permalink)
    +3 (3)
    Gort2015
    goto
     
    Really?


    Yes, GOTO. Try writting (useful) assembly code without it. In fact if you write in c (or nearly any language) you are using lots of GOTOs, you just don't see them. (break statement as an example)
    Like any instruction, GOTO if used correctly and with care is perfectly OK. Note the qualifiers in that statement, I am NOT trying to start a long winded discussion on the merits of the GOTO satement in higher level languages.
    #10
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2645
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: goto label 2018/02/05 09:51:08 (permalink)
    -1 (1)
    I do write asm.
     
    With a top down approach there is no need to use goto, I never have since the early days of BASIC.
     
    What next, peek and poke?

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #11
    jack@kksound
    code tags!
    • Total Posts : 2736
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: goto label 2018/02/05 10:07:53 (permalink)
    +2 (2)
    Gort2015
    I do write asm.
     
    With a top down approach there is no need to use goto, I never have since the early days of BASIC.
     
    What next, peek and poke?


    My point is that the GOTO instruction is used by the compiler, even if the programmer does not realize it. It is inherent in the implimentation of nearly all control structures (switch, while, for..next, etc) at the assembly level. IMHO it can be used in some situations to the programs advantage, possibly resulting in smaller or less complicated looking code (and yes it usually results in the opposite, a mess of "spaghetti code" that is impossible to read or debug). Been doing this for about 50 years and heard all the arguments for and against the use of GOTO in high level languages and honestly don't agree with most of them.
    #12
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2645
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: goto label 2018/02/05 10:31:32 (permalink)
    -2 (2)
    I don't agree with goto at all, it's bad programming in C.  It breaks the top down approach.
     
    Maybe you are thinking of 8bit instruction sets that only have a handful of instructions.
    The only time I use asm goto or asm call is if calling external libraries that will not fit into a relative branch since they could be anywhere in memory.
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #13
    jack@kksound
    code tags!
    • Total Posts : 2736
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: goto label 2018/02/05 10:59:23 (permalink)
    +2 (2)
    As I said, I have heard most (if not all) arguments for and against, don't really care and don't want a long discussion. It is all opinion and that is OK. If you don't like it don't use it. But to claim it is "bad programming" so don't use it is just dogmatic.
    And yes, I have programmed for many types of processors, some with relative branch instructions and some without. I have written programs in c, Fortran, Basic, Prolog, Pascal, assembly of many types, 8 bits, 4 bits, 16 bits, 64 buts, analog (yep that too), any many others I forget (or would like to) and this GOTO question comes up all the time witht he same arguments. It is academic. Use the instruction if it works for you, don't use it if it doesn't .
    And oh, by the way, how do you program a control structure (any type of loop) that is larger then a relative branch will handle without using a GOTO somewhere in the code (at the assembly level)? Sure it can be done but it will be a lot more complicated then a simple GOTO will be. No need to actually answer that question, I leave it as an exercise.
    #14
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2645
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: goto label 2018/02/05 11:28:15 (permalink)
    0
    Revolution 1777 posts.
     
    I don't why you keep mentioning assembler.
     
    Anyhow I'm now off to get a KFC, Fancy a Tenancy Hot.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #15
    1and0
    Access is Denied
    • Total Posts : 8337
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: goto label 2018/02/05 11:28:38 (permalink)
    0
    Like someone said, you have to know what you are doing. ;)  IMO, why limit yourself?!
     
    #16
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2645
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: goto label 2018/02/05 15:03:23 (permalink)
    0
    Don't ask me absurd questions, it's not my first Rodeo.
     
    The thread is about goto in C.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #17
    1and0
    Access is Denied
    • Total Posts : 8337
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: goto label 2018/02/05 21:40:52 (permalink)
    +1 (1)
    As pointed out, a break statement is really a goto in disguise, so are a continue statement and sometimes even a return statement. Goto has its place and can be useful in C, and I'll use it when it's the right tool for the job, like when resulting in more readable or more efficient code; e.g. breaking out nested loops, etc. Sure, there are ways to avoid goto but it might make the code harder to read and less efficient.
     
    #18
    NorthGuy
    Super Member
    • Total Posts : 5017
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: goto label 2018/02/05 22:05:52 (permalink)
    0
    When I was young, someone tought me to avoid gotos and I followed the advise. I wish I didn't.
    post edited by NorthGuy - 2018/02/05 22:08:57
    #19
    1and0
    Access is Denied
    • Total Posts : 8337
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: goto label 2018/02/06 04:38:58 (permalink)
    +1 (1)
    NorthGuy
    When I was young, someone tought me to avoid gotos and I followed the advise. I wish I didn't.

    When I was young I heard the same advice.  Now I'm older and hopefully a little wiser, and maybe more foolish too. ;)
    post edited by 1and0 - 2018/02/06 04:42:36
    #20
    Page: 12345.. > >> Showing page 1 of 6
    Jump to:
    © 2018 APG vNext Commercial Version 4.5