label not allowed at end of construct?

W

Wiseguy

I'm in the process of trying to create my own lean, mean, uber
linux distro and have bootstrapped a prototype system to build upon.
I'm using the gcc 3.4.3 compiler and am getting an error that I have
to question.

Some of the code I'm compiling places labels at the end of a construct,
either as the destination of a goto or even something as benign as a
default: label in a switch statement.

starting with 3.4.3 (but not before) I'm seeing a compiler error
about not being allowed to place a label directly before the
ending brace of a construct like

label:
}

or

case 'a': break;
default:
}

What's the deal? Whether it is good form or not, I cannot see any
legitimate reason why I would be prohibited from doing this? Is there
a difference in requirements between c and c++ where this is concerned?
should I look for a compiler switch to disable this behavior?
 
A

Alan Brown

I'm in the process of trying to create my own lean, mean, uber
linux distro and have bootstrapped a prototype system to build upon.
I'm using the gcc 3.4.3 compiler and am getting an error that I have
to question.

Some of the code I'm compiling places labels at the end of a
construct, either as the destination of a goto or even something as
benign as a default: label in a switch statement.

starting with 3.4.3 (but not before) I'm seeing a compiler error
about not being allowed to place a label directly before the
ending brace of a construct like

label:
}

or

case 'a': break;
default:
}

What's the deal? Whether it is good form or not, I cannot see any
legitimate reason why I would be prohibited from doing this? Is there
a difference in requirements between c and c++ where this is
concerned? should I look for a compiler switch to disable this
behavior?


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the
World! 120,000+ Newsgroups ----= East and West-Coast Server Farms -
Total Privacy via Encryption =----

A label indicates the next EXECUTABLE statement that control is passed to.
The closing brace of a construct is not an executable statement.

"In C++ (as in C), a label is just a name followed by a colon:)). The
label is placed to the left of a legal C++ statement, and a jump is
accomplished by writing goto followed by the label name."
from 'Sams Teach Yourself C++ in 24 Hours' by Liberty & Horvath.

You could try

{
......
labelname: {}
}

as if the label is attached to an empty statement block.

Is default (in your example) truely a label or part of the switch
construct? I think it is the latter.

Alan
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top