how to use a label??

V

void * clvrmnky()

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

Michael Mair

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
 
N

Neil

hisam said:
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();
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top