hisam said:
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