- C language
- Basic grammar
- here
Read header file
I will explain how to read the header file using the include macro.
#include header file name
The header file name is written as "
#include <stdio.h>
If you want to read the header of the library from a location other than the system header file reading path in your own library, write "" header file name "".
#include "mylib.h"
Is it possible to read other than the header file?
Yes. It is possible to read other than the header file. But perhaps, basically, that's not what you want. If you're just starting out in C and think you need to read something other than a header file, stop for a moment and think about it.
One use is to see an example where a large amount of static data is defined(such as Unicode character definition) because you want to keep the files separate.
Where is the read path for the system header file defined?
One of the system header read paths is "/ usr / include" in Ubuntu, for example. It may be different for other UNIX / Linux distributions.
How can I find out the read path of the system header file?
In fact, the header file read path is written to the C preprocessor.
First, find out the path of the preprocessor used by gcc.
gcc -print-prog-name = cc1
The output is as follows.
/ usr / lib / gcc / x86_64-linux-gnu / 7 / cc1
When viewing the preprocessor version, the include path is displayed.
/ usr / lib / gcc / x86_64-linux-gnu / 7 / cc1 -v
The default header file read path is displayed.
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: / usr / lib / gcc / x86_64-linux-gnu / 7 / include / usr / local / include / usr / lib / gcc / x86_64-linux-gnu / 7 / include-fixed / usr / include
Why can the standard library use functions just by reading the header file?
Normally, you have to read the header file and link the library or object file before you can use the function.
For C language standard libraries such as "stdio.h", this work is not necessary.
In fact, when an executable is generated by gcc linking, a library called glibc (libc) that implements C language functions is linked.
What is a macro?
A C language macro is a syntax that starts with #. The description of the macro is expanded into the source code by the C language processor before the source code begins to compile.