By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,985 Members | 2,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,985 IT Pros & Developers. It's quick & easy.

how to use a label??

P: n/a
How to use a label in c?? also how to call???

Apr 18 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
hisam wrote:
How to use a label in c?? also how to call???

Any C book will tell you how to do this. Maybe try Google if you do not
have a paper book.
Apr 18 '06 #2

P: n/a
hisam schrieb:
How to use a label in c?? also how to call???


From the C99 standard:

,-- 6.8.1 Labeled statements --
Syntax
1
labeled-statement:
identifier : statement
case constant-expression : statement
default : statement

Constraints
2 A case or default label shall appear only in a switch statement.
Further constraints on such labels are discussed under the switch
statement.
3 Label names shall be unique within a function.
Semantics
4 Any statement may be preceded by a prefix that declares an
identifier as a label name.
Labels in themselves do not alter the flow of control, which
continues unimpeded across them.
`----

Usage with goto: Labels have to precede a statement (not a
declaration) and are visible within a function, regardless of
nesting of block scopes.

Example [untested]:

int main (void)
{
int i;

loopinit:
i = 0;
loopcontinuation:
if (i < 10)
goto loopend;
{
/* Do something */
if (i==5)
goto loopupdate;
/* Do something else */
}
loopupdate:
i++;
goto loopcontinuation;
loopend:
;

return 0;
}

Obviously,
int main (void)
{
int i;

for (i = 0; i < 10; i++)
{
/* Do something */
if (i==5)
continue;
/* Do something else */
}

return 0;
}
is easier on the eye.

Case/default labels are visible only for the switch statement
they belong to. Untested example:

int main (void)
{
int i = 6, j = 7, k = 0;

switch (i) {
case 0:
j *= -1;
break;
case 6:
switch (j) {
case 0:
k = 7;
break;
case 7:
k = i*j;
break;
}
break;
default:
j = 23;
}
switch (k) {
case 7:
/* Whatever */
break;
case 42:
/* Yep */
break;
default:
/* Boring */
break;
}

return 0;
}
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Apr 18 '06 #3

P: n/a
hisam wrote:
How to use a label in c?? also how to call???

C has labels

ALabel:

C has goto

goto ALabel;

C does not have call it has functions. BASIC has call.

To invoke a function just use its name

AFunction();
Apr 19 '06 #4

P: n/a
On 18 Apr 2006 12:30:29 -0700, "hisam" <mh*********@gmail.com> wrote:
How to use a label in c?? also how to call???


Others have told you how to use a label. I'll tell you when to use
one: after at least a couple more years of C programming, when there's
no good alternative. In the meantime, read
http://www.acm.org/classics/oct95/

--
Al Balmer
Sun City, AZ
Apr 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.