What does this “label” mean in C++?

后端 未结 4 1845
北荒
北荒 2021-01-23 03:34

I was reading some c++ code, and i saw something interesting.

The code was something like this:

repeat:
    ...code here....
fallback:
    ...code here.         


        
相关标签:
4条回答
  • 2021-01-23 03:57

    Labels are used with goto and switch/case statements, when they are used to direct the flow of control. However, labels may also be used absent any goto statements (case labels must only appear in a switch statement) as means of identifying particular code segments -- i.e., somewhat like a comment, though in reality more like a title. If you're not seeing any switch or goto statements, I suspect the code author is simply using them to organize his code.

    0 讨论(0)
  • 2021-01-23 03:58

    Labels are used as targets for goto, but, if you put a label, you are not forced to use goto, if you do not see any goto in the code you are reading, the people/guy who wrote that code probably used them for actually labeling purposes (duh!).

    0 讨论(0)
  • 2021-01-23 04:07

    It is a label, to which you can jump using a goto.

    Whether one should use gotos in a program is another matter entirely.

    0 讨论(0)
  • 2021-01-23 04:21

    A label is generally the target of a goto in C++.

    0 讨论(0)
提交回复
热议问题