For which situations can this definition be useful?
#ifndef __IMAGE_H__ #define __IMAGE_H__ //////////////////// #endif These directives are designed to protect against multiple inclusion in the presence of a complex hierarchy of included files - if such a file has already been included somewhere before, then __IMAGE_H__ will be declared, which means that the conditional #define will be skipped, along with all declarations before #endif
Some compilers have similar #pragma actions, for example,
#pragma once But the conditional version is the most universal.
#pragma once , so de facto this can be considered standard functionality - ixSciThis is the same classic include guard , which protects against re-including header files so that the same functions / classes are not overridden.
This is usually done in header files included by include . If the header file is included in the program twice, it will cause a bunch of "re-announcement" errors. To prevent this from happening, this define declares the flag that the file is already included and therefore, when it is re-enabled, ifndef will not work and the entire contents of the file will be ignored.
Source: https://ru.stackoverflow.com/questions/483235/
All Articles