Preprocessor

Include Directive

#include "<path>"
#include < <path> >

The #include directive inserts the contents of another file. The included file is referenced by its path. Typically, it is used to “import” commonly used code like e.g. libraries. Its behavior is similar to the C-Preprocessor.

Example:

In the following example file a.nc includes file b.nc. On execution of a.nc the interpreter internally replaces the include-line by the text of b.nc. Therefore, executing the program a.nc has the same effect as executing the program c.nc.

FILE a.nc:

G01 X0 Y0 F6000
#include "b.nc"
G01 X0 Y100

FILE b.nc:

G01 Z-2
G01 X100
G01 Z2

FILE c.nc:

G01 X0 Y0 F6000
G01 Z-2
G01 X100
G01 Z2
G01 X0 Y100

Example:

The following example assumes that the searchpath is set to the directories c:\jjj and c:\kkk. The file aaa.nc consists of a sequence of #include-directives that are explained in the following.

FILE c:\mmm\aaa.nc:

#include "c:\nnn\bbb.nc"
#include "ccc.nc"
#include "ooo\ddd.nc"
#include "..\ppp\qqq\eee.nc"
#include <fff.nc>
#include <../rrr/ggg.nc>
Preprocessor 1:

It is typically bad practice to include a file multiple times. Especially, if this feature is misused to factor out code. Instead, a function should be preferred to define code that is reused multiple times (see section Userdefined Functions).

Example:

In the following example file a.nc includes file b.nc twice. The second inclusion is always expanded, independently of the enclosing condition by the IF-THEN expression. The included file b.nc itself includes file c.nc.

FILE a.nc:

G01 X100 F6000
#include "b.nc"
G01 Y100
! IF stVariable=47 THEN
#include "b.nc"
! END_IF;

FILE b.nc:

#include "c.nc"
G01 X0 Y0

FILE c.nc:

G01 Z0

Example:

File x.nc demonstrates a series of invalid include directives. The first three lines violate the rule that each include directive must be denoted on a dedicated line. In lines 4 and 5 the filename is not properly enclosed in quotation marks or angle brackets. In line 6 a nonexisting file is included. Line 7 violates the rule that the include directive always has to be placed at the first position of a line. Line 8 includes the file y.nc, which itself includes file x.nc. This loop is reported as an error.

FILE x.nc:

#include "a.nc" G01 X100
! #include "a.nc"
#include "a.nc"    #include "b.nc"
#include a.nc
#include "a.nc>
#include "non_existing_file.nc"
    #include "a.nc"
#include y.nc

FILE y.nc:

#include "x.nc"