178
Manual – IPOSplus®
14
#include
Compiler – Programming
In addition to the '#ifndef' statement, there is also the '#ifdef' (ifdefined) statement. This
statement does not have to be negated. An if-else construction is also possible. In this
case, this means that the part of the statement following the "#else" is processed if the
"#ifdef" or "#ifndef" query is not fulfilled. This results in the following possibilities:
Note that these preprocessor statements can also be used to good effect in the main
program, not just in header files. As a result, for example, parts of a program can be con-
verted specifically for a machine without having to make major changes to the source
text.
14.3 #include
This directive makes it possible to incorporate source texts from other files (header files)
into the source text file. Header files are usually used to define constants or macros that
are used several times so they are available in different projects. The syntax is:
#include <FileName>
FileName is the complete name of the file that is to be incorporated. It is enclosed by
pointed brackets. It is sufficient to state the file name without path information if the file
to be incorporated is located in the current folder
The #include directives can also be used in nested structures, i.e. an included file can
itself contain an #include directive to include another file. Ensure that files do not set up
an include loop (they include themselves). This leads to a preprocessor error. We rec-
ommend avoiding nesting #include directives to keep the structure clearer.
#ifdef identifier_1
Program text_1
#else
Program text_2
#endif
#ifndef identifier_2
Program text_3
#else
Program text_4
#endif
#ifdef identifier_3
Program text_5
#endif
The file BEISPIEL.IPC contains the main program. The file CONST.H is a header file.
#include <CONST.H>
H10 = MAXIMUM_SPEED;
#define MAXIMUM_SPEED 3000
The preprocessor replaces the #include directive with the
content of the CONST.H file:
#define MAXIMUM_SPEED 3000
H10 = MAXIMUM_SPEED
The result after macro expansion is as follows:
H10 = 3000;