First come to recall how the macro is defined in the C language, the most basic is the definition of constants: #define Max_len 1024 This is the simplest constant macro definition, where the macro name is capitalized, the macro name will be replaced by the following value at Precompilation (Precompiled Four steps: 1, replace the macro name with the value after the macro name; 2 , load the contents of the included header file, 3, judge the logic false, and remove the logic false code; 4, delete the comment).
C language Macro function definition format: #define FUN_NAME (A, B, c) (function body) It is worth mentioning that the last one in the parameter is the return value; All the code in the function body must be displayed on one line, so a range character (backslash \) and the drive must follow the ENTER key. Otherwise, the battery life is not used;
Here is an example of the macro function, which is immediately followed by the previous blog jump question: If the same function is loaded repeatedly, and the function contains ASM assembly and the use of the tag location jump, then the program will report an error. Now let's do this with the macro function:
#define GREATER (A, B, result) ({ asm ("CMP%1,%2\n\t" "Jge ff\n\t" \ ///If an error is made, replace the FF with 0f "movl%1,%0\n\t" c5/> "jmp ef\n" \/ /If error, replace EF with 1f "ff:\n\t" \/ /If error, replace FF with 0 "movl%2,%0\n" "EF:" \/ /If error , replace EF with 1 : "=r" (Result) : "R" (a), "R" (b));}) void Fun1 () { int a = 2; int b = n; int ret = 0; GREATER (A, B, ret); printf ("Greater result is:%d\n", ret); } int Main () { fun1 (); int i = 1; int j =; int result = 0; GREATER (I,j,result); printf ("Greater result is:%d\n", result); return 0; }
C Program code embedded as assembly (four, macro function)