Including and using gprolog.h
Author: Daniel Diaz
Keywords: GNU Prolog, manual, Prolog, compiler, constraints, finite domains

### 10.2 Including and using gprolog.h

The C code should include gprolog.h which provides a set of C definitions (types, macros, prototypes) associated to the API. Include this files as follows:

      #include <gprolog.h>

If the installation has been correctly done nothing else is needed. If the C compiler/preprocessor cannot locate gprolog.h pass the C compiler option required to specify an additional include directory (e.g.-Iinclude_dir) to gplc as follows (section 4.4.3):

  % gplc -C -Iinclude_dir ...

The file gprolog.h declares the following C types:

- PlBool as an integer and the constants PL_FALSE (i.e. 0) and PL_TRUE (i.e. 1).
- PlLong as an integer able to store a pointer (equivalent to intptr_t). This type appeared in GNU Prolog 1.4.0 in replacement of long to support Windows 64 bits (where the long type is only 32 bits). This type is used to handle integer types.
- PlULong same as PlLong but unsigned (same as uintptr_t).
- PlTerm same as intptr_t. This type is used to store general Prolog terms.

New in GNU Prolog 1.3.1 and backward compatibility issues: in GNU Prolog 1.3.1 the API has been modified to protect namespace. The name of public functions, macros, variables and types are now prefixed with Pl_, PL_ or pl_. All these prefixes should be avoided by the foreign C-code to prevent name clashes. To ensure a backward compatibility, the names used by the old API are available thanks to a set of #define. However, this deprecated API should not be used by recent code. It is also possible to prevent the definition of the compatibility macros using:

      #define __GPROLOG_FOREIGN_STRICT__
      #include <gprolog.h>

In addition, gprolog.h defines a set of macros:

- __GNU_PROLOG__ (as the major version).
- __GPROLOG__, __GPROLOG_MINOR__ and __GPROLOG_PATCHLEVEL__. Their values are the major version, minor version, and patch level of GNU Prolog, as integer constants. For example, GNU Prolog 1.3.2 will define ____GPROLOG__ to 1, ____GPROLOG_MINOR__ to 3, and ____GPROLOG_PATCHLEVEL__ to 2.

  If you need to write code which depends on a specific version, you must be more careful. Recall these macros appeared in GNU Prolog 1.3.1 (undefined before), each time the minor version is increased, the patch level is reset to zero; each time the major version is increased (which happens rarely), the minor version and patch level are reset.

- __GPROLOG_VERSION__: the version as an integer defined as follows: major * 10000 + minor * 100 + patch level. For example: version 1.3.2 will result in the value 10302.
- PL_PROLOG_DIALECT: a C constant string (generally "gprolog"). Appeared in 1.3.2.
- PL_PROLOG_NAME: a C constant string (generally "GNU Prolog").
- PL_PROLOG_VERSION: a C constant string associated to the version (e.g. "1.4.0").
- PL_PROLOG_DATE: a C constant string associated with the date of this version (e.g. "Mar 29 2011".
- PL_PROLOG_COPYRIGHT: a C constant string associated with the copyright of this version (e.g. "Copyright (C) 1999-2021 Daniel Diaz".

Note the above PL_PROLOG_... macros are also accessible via Prolog flags thanks to the built-in predicate current_prolog_flag/2 (section 8.22.2)

Copyright (C) 1999-2021 Daniel Diaz Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. More about the copyright