[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GPC, like UCSD Pascal and BP, treats comments beginning with a
`$' immediately following the opening `{' or `(*' as
a compiler directive. As in Borland Pascal, {$...}
and
(*$...*)
are equivalent. When a single character plus a
`+' or `-' follows, this is also called a compiler switch.
All of these directives are case-insensitive (but some of them have
case-sensitive arguments). Directives are local and can be changed
during one compilation (except include files etc. where this makes
no sense).
In general, compiler directives are compiler-dependent. (E.g., only
the include directive {$I FileName}
is common to UCSD and
BP.) Because of BP's popularity, GPC supports all of BP's compiler
directives (and ignores those that are unnecessary on its platforms
-- these are those not listed below), but it knows a lot more
directives.
Some BP directives are -- of course not by chance -- just an
alternative notation for C preprocessor directives. But there are
differences: BP's conditional definitions
(`{$define Foo}') go into another name space than the
program's definitions. Therefore you can define conditionals and
check them via {$ifdef Foo}
, but the program will not see
them as an identifier `Foo', so macros do not exist in Borland
Pascal.
GPC does support macros, but disables this feature when the `--no-macros' option or the dialect option `--borland-pascal' or `--delphi' is given, to mimic BP's behaviour. Therefore, the following program will react differently when compiled with GPC either without special options or with, e.g., the `--borland-pascal' option (and in the latter case, it behaves the same as when compiled with BP).
program MacroDemo; |
Of course, you should not rely on such constructs in your programs. To test if the program is compiled with GPC, you can test the `__GPC__' conditional, and to test the dialect used in GPC, you can test conditionals like `__BORLAND_PASCAL__'.
In general, almost every GPC specific command line option (see section 7.1 GPC options besides those of GCC.) can be turned into a compiler directive (exceptions are those options that contain directory names, such as `--unit-path', because they refer to the installation on a particular system, and therefore should be set system-wide, rather than in a source file):
--foo {$foo} --no-foo {$no-foo} -Wbar {$W bar} { note the space after the `W' } -Wno-bar {$W no-bar} |
The following table lists some such examples as well as all those directives that do not correspond to command-line options or have syntactical alternatives (for convenience and/or BP compatibility).
--[no-]short-circuit $B+ $B- like in Borland Pascal: $B- means short-circuit Boolean operators; $B+ complete evaluation |
You also can use the preprocessor directives in C style, e.g. `#include', but this is deprecated because of possible confusion with Borland Pascal style `#42' character constants. Besides, in the Pascal style, e.g. `{$include "foo.bar"}', there may be more than one directive in the same line.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |