Given a function, let's say atoi, how can I find the header file I should include if I want to use this function ? I'm always get puzzled for that issue. If let me treat function like "atoi" as linux c api, I can put my question in another way as : Is a document for linux c api ?
Most standard headers are stored in /usr/include . It looks like stdbool. h is stored somewhere else, and depends on which compiler you are using. For example, g++ stores it in /usr/include/c++/4.7.
To check if an header file has been included or not in a C or C++ code, we need to check if the macro defined in the header file is being defined in the client code. Standard header files like math. h have their own unique macro (like _MATH_H ) which we need to check. Consider this example of checking if math.
The stdarg. h header file includes a function for the variable number of arguments.
1. Definition. Header File is the file where all the headers name are mentioned that going to be used or consumed in the main code file. On other hand Library is the file where the implementation code of each header is written down which is mentioned in the Header file.
Man pages. Type man atoi
(or, in general, man <function>
) at your command prompt. It will give you usage information as well as a listing of which headers to include.
Man pages also document programs and commands (find, grep, cd, etc.). Sometimes you may run into a case where a program has the same name as a C function (e.g. write). In that case, you need to direct man to look in the correct section of the manual, section 2 for system calls and section 3 for library functions. You do this by inserting the section number between "man" and the command name: man 2 write
. If you do not know whether a given function is a system call or a library function, try both.
You can learn more about manual pages by typing man man
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With