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

2020-04-20 04:59发布

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

The code was something like this:

repeat:
    ...code here....
fallback:
    ...code here....
start:
        ....another code....

This is the first time i am seeing this kind of "labels" in c++ code, i called the labels cos i have seen something similar in assembly code where the code is divided into sections with different titles which end with colon.

I am asking you what does that mean, and of what use it can be ?

标签: c++
4条回答
迷人小祖宗
2楼-- · 2020-04-20 05:12

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

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

查看更多
贪生不怕死
3楼-- · 2020-04-20 05:17

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

查看更多
够拽才男人
4楼-- · 2020-04-20 05:26

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!).

查看更多
Animai°情兽
5楼-- · 2020-04-20 05:28

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.

查看更多
登录 后发表回答