Labels have a substatement?

  • Thread starter Johannes Schaub (litb)
  • Start date
J

Johannes Schaub (litb)

Hello all. I wonder what the reason is for labels having a substatement?

int main() {
...
goto end;
....
end:
}

That's not allowed because it needs a trailing statement after "end:", like
the null statement ";". What is the reason that "foo:" is not a single
statement, that can be combined in compound statements with other
statements? I can only think of one case:

if(1)
foo: bar; // won't work if labels are leaf statements

Is there any more compelling reason behind this?
 
R

robertwessel2

Hello all. I wonder what the reason is for labels having a substatement?

int main() {
..
goto end;
...
end:

}

That's not allowed because it needs a trailing statement after "end:", like
the null statement ";". What is the reason that "foo:" is not a single
statement, that can be combined in compound statements with other
statements? I can only think of one case:

if(1)
  foo: bar; // won't work if labels are leaf statements

Is there any more compelling reason behind this?


It's actually the other way around - a statement can have an optional
label. Which explains the requirement you described.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top