Local Labels in C Last Updated : 08 May, 2017 Comments Improve Suggest changes Like Article Like Report Everybody who has programmed in C programming language must be aware about "goto" and "labels" used in C to jump within a C function. GCC provides an extension to C called “local labels”. Conventional Labels vs Local Labels Conventional labels in C have function scope. Where as local label can be scoped to a inner nested block. Therefore, conventional Labels cannot be declared more than once in a function and that is where local labels are used. A label can appear more than once in function when the label is inside a macro and macro is expanded multiple times in a function. For example if a macro funcMacro() has definition which involves jump instructions (goto statement) within the block and funcMacro is used by a function foo() several times. C #define funcMacro(params …) do { \ if (cond == true) \ goto x; \ <some code > \ \ x: \ <some code> \ } while(0); \ Void foo() { <some code> funcMacro(params …); <some code > funcMacro(params…); } In such a function foo() , the function macro will be expanded two times. This will result in having more than one definition of label ‘x’ in a function, which leads to confusion to the compiler and results in compilation error. In such cases local labels are useful. ? The above problem can be avoided by using local labels. A local label are declared as below: __label__ label; Local label declarations must come at the beginning of the block, before any ordinary declarations or statements. Below is C example where a macro IS_STR_EMPTY() is expanded multiple times. Since local labels have block scope and every expansion of macro causes a new do while block, the program compiles and runs fine. C #include <stdio.h> #include <string.h> //Function macro using local labels #define IS_STR_EMPTY(str) \ do { \ __label__ empty, not_empty, exit; \ if (strlen(str)) \ goto not_empty; \ else \ goto empty; \ \ not_empty: \ printf("string = %s\n", str); \ goto exit; \ empty: \ printf("string is empty\n"); \ exit: ; \ } while(0); \ int main() { char string[20] = {'\0'}; //Pass empty string to Macro function IS_STR_EMPTY(string); //Pass non-empty string to Macro function strcpy(string, "geeksForgeeks"); IS_STR_EMPTY(string); return 0; } Output: string is empty string = geeksForgeeks Comment More infoAdvertise with us Next Article Local Labels in C K kartik Improve Article Tags : C Language Similar Reads Local Variable in C In C language, a variable declared within a function or a block of code is called a local variable. Local variables are frequently used to temporarily store data in a defined scope where they can be accessed and manipulated. They are stored in the memory stack, Once the function or block of code in 3 min read scanf in C In C, scanf() is a function is used to read data from stdin (standard input stream i.e. usually keyboard) and stores the result into the given arguments. It is defined in the <stdio.h> header file.Example:C#include <stdio.h> int main() { int n; // Reading an integer input scanf("%d", 3 min read Lexical Analyser in C In C, the lexical analysis phase is the first phase of the compilation process. In this step, the lexical analyzer (also known as the lexer) breaks the code into tokens, which are the smallest individual units in terms of programming. In the lexical analysis phase, we parse the input string, removin 6 min read C - File I/O In this article, we will learn how to operate over files using a C program. A single C file can read, write, move, and create files in our computer easily using a few functions and elements included in the C File I/O system. We can easily manipulate data in a file regardless of whether the file is a 11 min read Tokens in C In C programming, tokens are the smallest units in a program that have meaningful representations. Tokens are the building blocks of a C program, and they are recognized by the C compiler to form valid expressions and statements. Tokens can be classified into various categories, each with specific r 4 min read Like