Talk C chestnuts together (124th back: C language instance-built-in macro)
Hello, everyone. In the previous session, we talked about the example of displaying variables and function addresses. This example is as follows:Built-in macros. When you leave the rest of your time, your words will go right. Let's talk C chestnuts together!
When compiling a program, if there is a syntax error, the compiler will prompt that there is an error in a row of a file. How does this happen? In fact, the built-in Macros in C language are used.
Speaking of macros, I think everyone knows that the so-called built-in macros are similar to the keywords of the C language. They are defined by the C language itself. Therefore, we can directly use them without defining macros. Common built-in macros"_ LINE _And_ FILE _". If you put them in the code, you can enter the row number and file name of their location. When the compiler outputs incorrect file names and row numbers, they are used.
In fact, they are often used to add debugging information to files. Because the program we write will inevitably have errors, we need to debug the program. After adding a built-in macro to the file, we can quickly find the row in which the error occurred through debugging. In this way, errors in the program can be quickly modified to improve work efficiency.
Let's take a simple example to illustrate the use of built-in macros. The following is a detailed code for your reference:
#include
int show(){ printf("hello \n"); printf("file:%s line:%d \n",__FILE__,__LINE__); return 0;}int main(){ printf("file:%s line:%d \n",__FILE__,__LINE__); show(); return 0;}
In the code, we use a built-in macro to output the current file name and row number. The following is the running result of the program. For details, refer:
File: test. c line: 13 // This is the content in the main function. hello file: test. c line: 7 // This is the content in the show function.
Let's talk about the example of built-in macros. I want to know what examples will be provided later, and I will try again.