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


