#include

Syntax:

    #include filename

Explanation:

#include tells GCBASIC to open up another file, read all of the subroutines and constants from it, and then copy them into the current program.

There are two forms of include: absolute and relative.

Absolute is used to refer to files in the ..\GCBASIC\include directory. The name of the file is specified between < and > symbols. For instance, to include the file srf04.h, the directive is:

    #include <srf04.h>

With #option IncludePath (build 1661), the folders it names are searched first, in their order, and then the ..\GCBASIC\include directory. A project can keep its own libraries in a folder of its own and still include them with < and >.

Relative is used to read files in the same folder as the currently selected program. Filenames are given enclosed in quotation marks, such as where mycode.h is the name of the file that is to be read.

    #include "mycode.h"

NOTES: It is not essential that the include file name ends in .h - the important thing is that the name given to GCBASIC is the exact name of the file to be included.

Those who are familiar with #include in assembly or C should bear in mind that #include in GCBASIC works differently to #include in most other languages - code is not inserted at the location of the #include, but rather at the end of the current program.

See Also:

  • #insert — inserting code at the exact location of the directive instead
  • #option IncludePath — more folders for #include <…​>
  • Converters — converting non-GCBASIC data files before including them