liveBook · Manning

Label

As explained in Modern C

A label is a named position in assembler code that identifies a point to which control can refer or transfer.

A label names a position in code so control can refer to it or transfer to it. In C, labels and goto statements work together inside the same function. section 17.3

A label can repeat a block

RETRY: marks the position where execution resumes when goto RETRY is taken. The marked position is also relevant to object lifetime: an object defined in the surrounding block remains alive across the repeated execution, unlike an object defined inside a while statement. section 17.3

Labels have parallel roles at two language levels:

  • C labels identify destinations for goto within one function. section 17.3
  • Assembler labels identify points such as a function entry or a translated C goto destination; .L_AGAIN corresponds to the C label AGAIN. section 13.5
1   size_t* ip = 0
2   while(something)
3     ip = &(size_t){ fun() };        /* Life ends with while    */
4                                     /* Good: resource is freed */
5   printf("i is %d", *ip)            /* Bad: object is dead     */


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":1}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":10}],[{\"line\":2,\"ch\":13},{\"line\":2,\"ch\":19}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":1}],[{\"line\":1,\"ch\":4},{\"line\":1,\"ch\":9}],[{\"line\":2,\"ch\":56},{\"line\":2,\"ch\":61}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":1}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":10}],[{\"line\":2,\"ch\":13},{\"line\":2,\"ch\":19}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":1}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":1}],[{\"line\":4,\"ch\":4},{\"line\":4,\"ch\":10}]]"}
!@%STYLE%@!

Compare a loop-defined object with a goto-repeated block to see how the label changes execution structure and affects object lifetime. section 17.3

How Modern C covers it

How deep it goes
Explains C and assembler roles, then connects repeated execution to scope and lifetime without developing label syntax broadly.
Examples
Uses RETRY and AGAIN labels, goto repetition, compound literals, and fgoto assembler output.
What it assumes
Assumes familiarity with goto and basic C control flow while clarifying labels as their position-marking counterpart.
What you can do after
Evaluate how C labels redirect execution and how corresponding assembler labels identify machine-level program positions.
How it connects
Connects labels with goto, control flow, scope, object lifetime, assembler, functions, and compiler output.

Also explained in

Compare how 3 books explain label →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.