Home > Article > Backend Development > The difference between #ifndef and #define
#The difference between ifndef and #define
1. Different usage scenarios:
# The usage scenarios of ifndef are:
1. Used in header files to prevent header files from being called multiple times.
2. Use it as a test, eliminating the trouble of commenting the code.
3. Use it as a judgment for different roles or scenes.
#define usage scenarios:
Macro definition
2. Different meanings:
#ifndef means ifnotdefine.
#define means define.
Extended information:
#The effect of ifndef is to prevent a source file from containing the same header file twice, rather than to prevent two source files from containing the same header file. .
When compiling, these two C files must be compiled together into a executable file.
Put the contents of the header file in #ifndef and #endif. Regardless of whether the header file will be referenced by multiple files, this must be added.
The general format is like this:
#ifndef <标识> #define <标识>. ........... #endif<标识>
In theory, it can be freely named, but the "identification" of each header file should be unique. The naming rule for the
logo is generally that the header file name is in all capital letters, with underscores before and after, and the "." in the file name is also changed to underlines, such as:
#ifndef_STDIO_H_#define_STDIO_H_......#endif.
Recommended learning: c language video tutorial
The above is the detailed content of The difference between #ifndef and #define. For more information, please follow other related articles on the PHP Chinese website!