This chapter is under development, so don't be too excited about the paragraph below!
This chapter contains an alphabetical list of all built-in identifiers of the GNU Pascal compiler. It does not cover extensions provided by external libraries which are supposed to come with their own documentation.
Function abs ( i: integer type ): integer type;
or
Function abs ( x: real type ): real type;
or
Function abs ( z: complex type ): real type;
Returns the absolute value of the argument. For integer or real values of `x', the definition is
Function abs ( x: integer or real type ): integer or real type; begin (* abs *) if x < 0 then abs:= -x else abs:= x; end (* abs *);
whereas for complex values it is
Function abs ( x: Complex ): Complex; begin (* abs *) abs:= sqrt ( x * conjugate ( x ) ); end (* abs *);
The function `abs' is defined in ISO-7185 Standard Pascal; its application to complex values is defined in ISO-10206 Extended Pascal.
Program TestAbs; Var i1: Complex; begin writeln ( abs ( 42 ) ); (* 42 *); writeln ( abs ( -42 ) ); (* 42 *); writeln ( abs ( -12.1 ) : 0 : 1 ); (* 12.1 *); i1:= cmplx ( 1, 1 ); (* 1 + i *) writeln ( abs ( i1 ) : 0 : 3 ); (* 1.414, i.e. sqrt ( 2 ) *) end.
section sqr.
Var variable name: data type absolute variable reference;
or
Var variable name: data type absolute integer expression;
The first meaning of the `absolute' directive allows to put a variable to the address of another one and thus provides a type-casting mechanism.
In most cases, variable reference will be just a variable name, but GPC also allows arbitrary expressions here. If variable reference has neither a constant address nor is a variable parameter, GPC prints a warning. This warning is suppressed in "extended syntax" mode which is switched on by the `--extended-syntax' option or the `(*$X+*)' compiler directive.
Other type-casting mechanisms in GPC are variant records (which are valid in ISO-7185 Standard Pascal) and explicit type casts.
The second meaning of `absolute' places a variable at a specified address. This is useful on machines without virtual memory addressing for doing certain low-level operations, but should be avoided on systems with memory protection such as UNIX-like systems. GPC does not check whether the specified virtual address makes any sense and does not provide a built-in mechanism to map it to a real address.
GPC warns about this second use of `absolute' unless "extended syntax" has been requested.
ISO Pascal does not define `absolute'.
Borland Pascal does define `absolute' but has a slightly different syntax for the second meaning related to the addressing scheme of Intel X86 processors working in real mode.
Allowing arbitrary memory references instead of just variable names in the first meaning of `absolute' is a GNU extension.
Program TestAbsolute; (*$X+*) Const IOmemory = $F0000000; Var Mem: array [ 0..MaxInt ] of Byte absolute 0; SomeIOport: Byte absolute IOmemory + $C030; (* Beware: Using any of the variables above will crash *) (* your program unless you know exactly what you do! *) (* That's why GPC warns about it without the X+ directive. *) Var x: Real; a: array [ 1..SizeOf ( Real ) ] of Byte absolute x; i: Integer; b: Byte absolute a [ i ]; (* GNU extension: non-constant memory reference. *) begin x:= 3.14; (* Gather at the internal representation of a real variable. *) for i:= 1 to SizeOf ( Real ) do write ( a [ i ] : 4 ); (* Or (kind of abuse): `write ( b );' *) writeln; end.
section record, section Type Casts.
Function AlignOf ( Var x ): Integer;
Returns the alignment of a type or variable in bytes.
`AlignOf' is a GNU extension.
Var a: Integer; b: array [ 1..8 ] of Char; ... writeln ( AlignOf ( a ) ); (* Alignment of `Integer'; usually 4 bytes. *) writeln ( AlignOf ( b ) ); (* Alignment of `Char'; usually 1 byte. *)
Although the array is bigger than a single char, it is accessed char by char, so there usually is no need to align it on a 4 byte boundary or such. (This may be false on some platforms.)
section SizeOf, section BitSizeOf, section TypeOf.
`all' is a predefined export interface for Extended Pascal modules. You can use it to export all identifiers declared in an interface module automatically.
`all' is a GNU extension.
Module TestAll Interface; export foo = all; (* Same as `foo = ( a, b, bar );' *) Var a, b: Integer; Procedure bar; end.
section The Source Structure of ISO-10206 Extended Pascal Modules.
Operator and ( operand1, operand2: Boolean ) = result: Boolean;
or
Operator and ( operand1, operand2: integer type ) = result: integer type;
or
Procedure and ( Var operand1: integer type; operand2: integer type );
In GNU Pascal, `and' has three built-in meanings:
The logical `and' operator is defined in ISO-7185 Standard Pascal.
According to ISO, you cannot rely on `and' being a short-circuit operator. On the other hand, GPC's default behaviour does not contradict the ISO standard. (See section and_then.) However, since it seems to be a de-facto standard among ISO Pascal compilers to evaluate both operands of `and', GPC switches to `--no-short-circuit' mode if one of the language dialect options selecting ISO Pascal, for instance `--extended-pascal', is given. Use `--short-circuit' to override.
ISO Pascal does not define the bitwise `and' operator; Borland Pascal and Delphi do.
Use of `and' as a "procedure" is a GNU extension.
Var a, b, c: Integer; ... if ( a = 0 ) and ( b = 0 ) then (* logical `and' *) c:= 1 else if a and b = 0 then (* bitwise `and' *) c:= 2 else and ( c, a ); (* same as `c:= c and a' *)
Note the difference between the logical `and' and the bitwise `and': When `a' is 2 and `b' is 4, then `a and b' is 0. Beware: `a and b = 0' has nothing to do with `( a = 0 ) and ( b = 0 )'!
Since bitwise `and' has a higher priority than the `=' operator, parentheses are needed in `if ( a = 0 ) and ( b = 0 )' because otherwise `0 and b' would be calculated first, and the remainder would cause a parse error.
section and_then, section and then, section or, section xor, section Operators.
`and then' is an alias for the short-circuit logical operator `and_then'.
While `and_then' is defined in ISO-10206 Extended Pascal, `and then' is a GNU Extension.
Var p: ^Integer; [...] if ( p <> Nil ) and then ( p^ < 42 ) then (* This is safe. *) [...];
section and_then, section and, section or else.
Operator and_then ( operand1, operand2: Boolean ) = result: Boolean;
The `and_then' short-circuit logical operator performs the same operation as the logical operator `and'. But while the ISO standard does not specify anything about the evaluation of the operands of `and'---they may be evaluated in any order, or not at all---`and_then' has a well-defined behaviour: It evaluates the first operand. If the result is `false', `and_then' returns `false' without evaluating the second operand. If it is `true', the second operand is evaluated and returned.
Since the behaviour described above is the most effective way to implement `and', GPC by default treats `and' and `and_then' exactly the same. If you want, for some reason, to have both operands of `and' evaluated completely, you can specify the `--no-short-circuit' command-line option, but this is not portable. The portable way to have both operands evaluated is to assign both to temporary variables and then use `and'---or `and_then', it does not matter.
ISO-7185 Standard Pascal does not define `and_then'; ISO-10206 Extended Pascal does.
Some people think that the ISO standard requires both operands of `and' to be evaluated. This is false. What the ISO standard does say is that you cannot rely on a certain order of evaluation of the operands of `and'; in particular things like
Var p: ^Integer; [...] if ( p <> Nil ) and ( p^ < 42 ) then [...];
can crash according to ISO Pascal, although they cannot crash when compiled with GNU Pascal running in default mode.
If you want to write portable and efficient code in ISO-10206 Extended Pascal, always use `and_then'; never use `and'.
Var p: ^Integer; [...] if ( p <> Nil ) and_then ( p^ < 42 ) then (* This is safe. *) [...];
section and then, section and, section or_else.
Type AnsiChar = Char;
`AnsiChar' is an 8 bit char type. Currently, it is the same as `Char', but this might change in the future, once `wide chars' (16 bit chars) will be introduced into GPC. Depending on the platform, `Char' might be either `AnsiChar' or `WideChar' then.
ISO Pascal does not define `AnsiChar'; Delphi does.
Var A: AnsiChar; (* There is nothing special with `AnsiChar'. *) B: Char; [...] A:= 'A'; A:= B;
section pAnsiChar, section Char.
Procedure append ( Var F: any file );
`append' is a Borland Pascal extension. ISO-10206 Extended Pascal has section extend instead.
section Assign, section reset, section rewrite, section update, section extend.
Function arctan ( x: Real ): Real;
or
Function arctan ( z: Complex ): Complex;
`arctan' returns the (principal value of the) arcus tangent of the argument. The result is in the range `-pi / 2 < arctan ( x ) < pi / 2' for real arguments.
The function `arctan' is defined in ISO-7185 Standard Pascal; its application to complex values is defined in ISO-10206 Extended Pascal.
writeln ( 4 * arctan ( 1 ) : 0 : 5 ); (* yields 3.14159; arctan ( 1 ) = pi / 4. *)
section sin, section cos, section ln, section arg.
Function arg ( z: Complex ): Real;
`arg' returns the complex "argument", i.e. the angle (in radian) in the complex plane with respect to the real axis, of its parameter `z'. The result is in the range of `-pi < arg ( z ) <= pi'.
ISO-7185 Standard Pascal does not define `arg'; ISO-10206 Extended Pascal does.
Program TestArg; Var z: Complex; begin z:= cmplx ( 1, 1 ); (* 1 + i *) writeln ( arg ( z ) : 0 : 5 ); (* yields 0.78540, i.e. pi / 4. *) end.
section arctan, section ln, section polar.
(Under construction.)
(Under construction.)
(Under construction.)
Procedure Assign ( Var F: any file; FileName: String );
`Assign' is a Borland Pascal extension.
section reset, section rewrite, section update, section extend, section append.
(Under construction.)
(Under construction.)
(Under construction.)
Procedure Bind ( Var F: any file; B: BindingType );
(Under construction.)
(Under construction.)
Function Binding ( F: any file ): BindingType;
(Under construction.)
Type BindingType = packed record Bound, Extensions_valid, Readable, Writable, Existing: Boolean; Error, Size: Integer; CFile: Pointer; Name: String [ binding name length ]; end (* BindingType *);
Function BitSizeOf ( Var x ): Integer;
Returns the size of a type or variable in bits.
`BitSizeOf' is a GNU extension.
Var a: Integer; b: array [ 1..8 ] of Char; c: Integer ( 12 ); d: packed record x: Integer ( 12 ); y: 0..3; end (* d *); ... writeln ( BitSizeOf ( a ) ); (* Size of an `Integer'; usually 32 bits. *) writeln ( BitSizeOf ( b ) ); (* Size of eight `Char's; usually 64 bits. *) writeln ( BitSizeOf ( c ) ); (* 16 bits (smallest addressable space). *) writeln ( BitSizeOf ( d ) ); (* 16 *) writeln ( BitSizeOf ( d.x ) ); (* 12 *) writeln ( BitSizeOf ( d.y ) ); (* 2 *)
section SizeOf, section AlignOf, section TypeOf.
(Under construction.)
Procedure BlockRead ( Var F: File; Var Buffer; Blocks: Integer );
or
Procedure BlockRead ( Var F: File; Var Buffer; Blocks: Integer; Var BlocksRead: Integer );
(Under construction.)
Procedure BlockWrite ( Var F: File; Const Buffer; Blocks: Integer );
or
Procedure BlockWrite ( Var F: File; Const Buffer; Blocks: Integer; Var BlocksWritten: Integer );
(Under construction.)
(Under construction.)
`Byte' is an unsigned integer type which is one "unit" wide. On most platforms one unit has 8 bits, therefore the type is named "byte" and usually has a range of `0..255'. (It is the same as section ByteCard.)
`Byte' in GNU Pascal is compatible to `unsigned char' in GNU C.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `Byte'. (However see section Subrange Types.)
The `Byte' type appears in Borland Pascal and Delphi, too, where it is an unsigned 8-bit integer type.
section Integer Types, section Subrange Types.
(Under construction.)
`ByteCard' is an unsigned integer type which is one "unit" wide. On most platforms one unit has 8 bits, therefore the type is prefixed "byte-" and usually has a range of `0..255'.
`ByteCard' in GNU Pascal is compatible to `unsigned char' in GNU C.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `ByteCard'. (However see section Subrange Types.)
section Integer Types, section Subrange Types.
`ByteInt' is a signed integer type which is one "unit" wide. On most platforms one unit has 8 bits, therefore the type is prefixed "byte-" and usually has a range of `-128..127'.
`ByteInt' in GNU Pascal is compatible to `signed char' in GNU C.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `ShortInt'. (However see section Subrange Types.)
`ByteInt' in GNU Pascal corresponds to section ShortInt in Borland Pascal and Delphi.
section Integer Types, section Subrange Types.
(Under construction.)
(Under construction.)
(Under construction.)
Function Card ( S: any set ): Integer;
`Cardinal' is the "natural" unsigned integer type in GNU Pascal. On most platforms it is 32 bits wide and thus has a range of `0..4294967295'. Use it whenever you need a general-purpose unsigned integer type and don't need to care about compatibility to other Pascal dialects.
As an extension, GPC allows to use `Cardinal' as a pseudo-schema to produce types with a specified size in bits; for example
Type Card16 = Cardinal ( 16 );
defines an unsigned integer type with 16 bits. The same mechanism works for `Integer' and `Word', too.
`Cardinal' in GNU Pascal is compatible to `unsigned int' in GNU C.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `Cardinal'. (However see section Subrange Types.)
The `Cardinal' type appears in Delphi, too, where it has 16 bits in version 1.0, 32 from version 2.0 on.
section Integer Types, section Subrange Types.
(Under construction.)
(Under construction.)
(Under construction.)
Procedure ChDir ( Directory: String );
(Under construction.)
Function chr ( AsciiCode: Integer ): Char;
(Under construction.)
Procedure Close ( Var F: any file );
(Under construction.)
Function cmplx ( RealPart, ImaginaryPart: Real ): Complex;
`Comp' is a signed integer type which is longer than `Integer'. On most platforms it is 64 bits wide and thus has a range of `-9223372036854775808..9223372036854775807'.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `Comp'.
Borland Pascal and Delphi also define `Comp' as a 64-bit signed integer type. This compatibility is the reason why GPC supports `Comp'. In some contexts, the Borland compilers treat `Comp' as a "real" type--this behaviour is not supported by GPC.
section Integer Types, section Subrange Types.
(Under construction.)
(Under construction.)
Function Concat ( S1, S2: String ): String;
or
Function Concat ( S1, S2, S3: String ): String;
or
...
(Under construction.)
Function conjugate ( z: Complex ): Complex;
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
Function Copy ( S: String; FirstChar, Count: Integer ): String;
(Under construction.)
Function cos ( x: Real ): Real;
or
Function cos ( z: Complex ): Complex;
(Under construction.)
(Under construction.)
Function CString2String ( S: CString ): String;
(Under construction.)
Function Date ( T: TimeStamp ): packed array [ 1..date length ] of Char;
(Under construction.)
Procedure dec ( Var x: ordinal type );
or
Procedure dec ( Var x: ordinal type; amount: Integer );
(Under construction.)
(Under construction.)
Procedure DefineSize ( Var F: any file; NewSize: Integer );
(Under construction.)
Procedure Delete ( Var S: String; FirstChar, Count: Integer );
(Under construction.)
(Under construction.)
Dispose ( PointerVar: Pointer );
or
Dispose ( PointerVar: Pointer; tag field values );
or
Dispose ( ObjectPointerVar: Pointer; destructor call );
(Under construction.)
Operator div ( p, q: Integer ) = r: Integer;
The `do' reserved word is used in combination with other Pascal keywords in many ways. For description and examples see the relevant reference sections: `for', `while', `with', `to begin', `to end'.
`do' is defined in the ISO-7185 Standard Pascal and supported by all known Pascal variants.
section for, section while, section with, section to begin, section to end.
(Under construction.)
Type Double = Real;
(Under construction.)
(Under construction.)
(Under construction.)
Function empty ( Var F: any file ): Boolean;
(Under construction.)
(Under construction.)
Function eof ( Var F: any file ): Boolean;
or
Function eof: Boolean;
(Under construction.)
Function eoln ( Var F: any file ): Boolean;
or
Function eoln: Boolean;
(Under construction.)
(Under construction.)
Function eq ( S1, S2: String ): Boolean;
(Under construction.)
Procedure erase ( Var F: any file );
(Under construction.)
(Under construction.)
Function exp ( x: Real ): Real;
or
Function exp ( z: Complex ): Complex;
(Under construction.)
(Under construction.)
Procedure extend ( Var F: any file );
(Under construction.)
Type Extended = LongReal;
(Under construction.)
(Under construction.)
(Under construction.)
The `far' directive can be appended to a procedure or function heading but is ignored by GPC. It is there for Borland compatibility, only. (Since the GNU compilers provide a flat memory model, the distinction between `near' and `far' pointers is void.)
ISO Pascal does not define `far', Borland Pascal does.
Var p: Procedure; Procedure Foo; far; (* `far' has no effect in GPC *) begin (* Foo *) [...] end (* Foo *); [...] p:= Foo; (* Would also work without `far' in GPC. *)
section near.
(Under construction.)
Var FileMode: Integer;
(Under construction.)
(Under construction.)
Function FilePos ( Var F: any file ): Integer;
(Under construction.)
Function FileSize ( Var F: any file ): Integer;
(Under construction.)
Procedure FillChar ( Var Dest; Count: Integer; Value: Char );
or
Procedure FillChar ( Var Dest; Count: Integer; Value: Byte );
(Under construction.)
Procedure flush ( Var F: any file );
(Under construction.)
for ordinal variable := initial value to final value do statement
or
for ordinal variable := initial value downto final value do statement
or
for ordinal variable in some set do statement
(Under construction.)
(Under construction.)
Function frac ( x: Real ): Real;
Procedure FreeMem ( Var p: Pointer; Size: Cardinal );
or
Procedure FreeMem ( Var p: Pointer );
Releases a chunk of memory previously allocated using `GetMem'. The parameter Size is optional, and its value is ignored.
Since Extended Pascal's schemata provide a cleaner way to implement dynamical arrays and such, we recommend using `GetMem' and `FreeMem' only for low-level applications or for interfacing with other languages.
ISO Pascal does not define `FreeMem', Borland Pascal does and requires two parameters. `FreeMem' with only one parameter is a GNU extension.
See section GetMem
section GetMem, section Schema Types, section Dispose, section Mark, section Release.
(Under construction.)
(Under construction.)
Function ge ( S1, S2: String ): Boolean;
(Under construction.)
Procedure Get ( Var F: typed file );
Function GetFile ( F: file type ): Pointer;
GNU Pascal files internally contain a C `FILE' descriptor. `GetFile' returns a pointer to this, so you can pass it to external procedures or functions, perhaps written in C, that cannot handle Pascal files.
`GetFile' is a GNU extension.
Program Hello; Procedure fputs ( S: CString; someFile: Pointer ); C; begin fputs ( 'Hello, world!'^J, GetFile ( Output ) ); end.
section C, section CString, section Interfacing with Other Languages.
Procedure GetMem ( Var p: Pointeger; Size: Cardinal );
or
Function GetMem ( Size: Cardinal ): Pointer;
Allocates dynamical storage on the heap and returns a pointer to it in `p' or as the function result.
Since Extended Pascal's schemata provide a cleaner way to implement dynamical arrays and such, we recommend using `GetMem' and `FreeMem' only for low-level applications.
ISO Pascal does not define `GetMem', Borland Pascal does, but only as a procedure. `GetMem' as a function is a GNU extension.
The Borland-comatibility Unit `Graph' from the `BPcompat' package supports a `GetImage' and a `PutImage' procedure which need a variable of size `ImageSize' as a buffer. Since these are "black box" routines, the buffer can't reasonably be a schema providing a dynamical array. Instead, we have to use `GetMem' and `FreeMem' for dynamical memory allocation.
Program TestGetMem; uses Graph; Var Buffer: Pointer; Size: Cardinal; begin [...] Size:= ImageSize ( 10, 10, 60, 30 ); Buffer:= GetMem ( Size ); (* or: GetMem ( Buffer, Size ); *) GetImage ( 10, 10, 60, 30, Buffer^ ); [...] FreeMem ( Buffer ); (* or: FreeMem ( Buffer, Size ); *) [...] end.
section FreeMem, section New, section Schema Types.
(Under construction.)
Procedure GetTimeStamp ( Var T: TimeStamp );
(Under construction.)
(Under construction.)
Function gt ( S1, S2: String ): Boolean;
(Under construction.)
Procedure Halt;
or
Procedure Halt ( ExitCode: Integer );
(Under construction.)
Function high ( ordinal type or variable ): Integer;
or
Function high ( array type or variable ): Integer;
(Under construction.)
(Under construction.)
Function Im ( z: Complex ): Real;
The reserved word `import' in the import part of a program makes the program import an interface. The syntax is
Program foo; import bar1; bar3 ( baz1 => glork1 ) in 'baz.pas'; bar2 only ( baz2, baz3 => glork2 ); [...]
The `in' above tells GPC to look for the `Module' in the specified file; otherwise the file name is derived from the name of the interface by adding first `.p', then `.pas'---which only works if the name of the exported interface coincides with the file name.
The symbol `=>' denotes import renaming: The entity which is exported under the name `baz1' by the interface `bar3' will be known under the new name `glork1' in the program.
The `only' qualifier means that only the listed identifiers will be imported from the interface. Renaming works together with `only', too.
There must be at most one import part in a program.
The interfaces needn't be exported by Extended Pascal Modules but may be UCSD/Borland Pascal Units as well.
ISO-7185 Standard Pascal does not define `import' and Modules in general. These are defined in the ISO-10206 Extended Pascal standard.
GNU Pascal does not yet support `qualified' import.
section Module, section Unit, section uses.
(Under construction.)
(Under construction.)
(Under construction.)
Procedure inc ( Var x: ordinal type );
or
Procedure inc ( Var x: ordinal type; amount: Integer );
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
Var InOutRes: Integer;
(Under construction.)
Var InOutResStr: CString;
(Under construction.)
Var Input: Text;
(Under construction.)
Procedure Insert ( Source: String; Var Dest: String; Position: Integer );
(Under construction.)
Function int ( x: Real ): Real;
`Integer' is the "natural" signed integer type in GNU Pascal. On most platforms it is 32 bits wide and thus has a range of `-2147483648..2147483647'. Use it whenever you need a general-purpose signed integer type.
As an extension, GPC allows to use `Integer' as a pseudo-schema to produce types with a specified size in bits; for example
Type Int16 = Integer ( 16 );
defines an integer type with 16 bits. The same mechanism works for `Cardinal' and `Word', too.
`Integer' in GNU Pascal is compatible to `int' in GNU C.
There are lots of other integer types in GPC, see section Integer Types.
In ISO Pascal, `Integer' is the only built-in integer type. (However see section Subrange Types.)
section Integer Types, section Subrange Types.
(Under construction.)
(Under construction.)
Function IOresult: Integer;
(Under construction.)
(Under construction.)
Function LastPosition ( Var F: typed file ): Integer;
(Under construction.)
Function le ( S1, S2: String ): Boolean;
(Under construction.)
Function length ( S: String ): Integer;
(Under construction.)
Function ln ( x: Real ): Real;
or
Function ln ( z: Complex ): Complex;
(Under construction.)
Function LoCase ( Ch: Char ): Char;
`LongCard' is an unsigned integer type which is longer than `Cardinal'. On most platforms it is 64 bits wide and thus has a range of `0..18446744073709551615'.
`LongCard' in GNU Pascal is compatible to `long long unsigned int' in GNU C.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `LongCard'.
section Integer Types, section Subrange Types.
`LongInt' is a signed integer type which is longer than `Integer'. On most platforms it is 64 bits wide and thus has a range of `-9223372036854775808..9223372036854775807'.
`LongInt' in GNU Pascal is compatible to `long long int' in GNU C.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `LongInt'.
Borland Pascal and Delphi also define `LongInt', but it is a 32-bit signed integer type there (section Integer in GNU Pascal). Both Borland languages define section Comp as a 64-bit signed integer type which is also supported by GPC for compatibility.
section Integer Types, section Subrange Types.
`LongestCard' is GPC's longest-possible unsigned integer type. Currently, this is the same as section LongCard. On most platforms it is 64 bits wide and thus has a range of `0..18446744073709551615'.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `LongestCard'.
section Integer Types, section Subrange Types.
`LongestInt' is GPC's longest-possible signed integer type. Currently, this is the same as section LongInt. On most platforms it is 64 bits wide and thus has a range of `-9223372036854775808..9223372036854775807'.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `LongestInt'.
section Integer Types, section Subrange Types.
(Under construction.)
`LongestWord' is GPC's longest-possible unsigned integer type. Currently, this is the same as section LongWord. On most platforms it is 64 bits wide and thus has a range of `0..18446744073709551615'. (It is the same as section LongestCard.)
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `LongestWord'.
section Integer Types, section Subrange Types.
(Under construction.)
`LongWord' is an unsigned integer type which is larger than `Word'. On most platforms it is 64 bits wide and thus has a range of `0..18446744073709551615'. It is the same as section LongCard.
`LongWord' in GNU Pascal is compatible to `long long unsigned int' in GNU C.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `LongWord'.
section Integer Types, section Subrange Types.
(Under construction.)
Function low ( ordinal type or variable ): Integer;
or
Function low ( array type or variable ): Integer;
(Under construction.)
Function lt ( S1, S2: String ): Boolean;
(Under construction.)
Procedure Mark ( Var P: Pointer );
(Under construction.)
Function max ( x1, x2: ordinal or real type ): same type;
(Under construction.)
(Under construction.)
(Under construction.)
`MedCard' is an unsigned integer type which is not smaller than `Cardinal'. On most platforms it actually is the same as `Cardinal' and 32 bits wide and thus has a range of `0..4294967295'.
`MedCard' in GNU Pascal is compatible to `long unsigned int' in GNU C. This compatibility is the reason why `MedCard' exists.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `MedCard'.
section Integer Types, section Subrange Types.
`MedInt' is a signed integer type which is not smaller than `Integer'. On most platforms it actually is the same as `Integer' and 32 bits wide and thus has a range of `-2147483648..2147483647'.
`MedInt' in GNU Pascal is compatible to `long int' in GNU C. This compatibility is the reason why `MedInt' exists.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `MedInt'.
section Integer Types, section Subrange Types.
(Under construction.)
`MedWord' is an unsigned integer type which is not smaller than `Word'. On most platforms it actually is the same as `Word' and 32 bits wide and thus has a range of `0..4294967295'. It is the same as section MedCard.
`MedWord' in GNU Pascal is compatible to `long unsigned int' in GNU C. This compatibility is the reason why `MedWord' exists.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `MedWord'.
section Integer Types, section Subrange Types.
(Under construction.)
Function min ( x1, x2: ordinal or real type ): same type;
(Under construction.)
(Under construction.)
Procedure MkDir ( Directory: String );
(Under construction.)
Operator mod ( p, q: Integer ) = r: Integer;
(Under construction.)
(Under construction.)
Procedure move ( Const Source; Var Dest; Count: Integer );
(Under construction.)
Procedure MoveLeft ( Const Source; Var Dest; Count: Integer );
(Under construction.)
Procedure MoveRight ( Const Source; Var Dest; Count: Integer );
The `near' directive can be appended to a procedure or function heading but is ignored by GPC. It is there for Borland compatibility, only. (Since the GNU compilers provide a flat memory model, the distinction between `near' and `near' pointers is void.)
ISO Pascal does not define `near', Borland Pascal does.
Var p: Procedure; Procedure Foo; near; (* `near' has no effect in GPC *) begin (* Foo *) [...] end (* Foo *); [...] p:= Foo; (* Works, despite the `near'. *)
section far.
(Under construction.)
Function ne ( S1, S2: String ): Boolean;
(Under construction.)
Procedure New ( Var P: any pointer );
or
Procedure New ( Var P: pointer to a variant record; tag fields);
or
Procedure New ( Var P: pointer to a schema; discriminants);
or
Procedure New ( Var P: pointer to an object; constructor call);
or
Function New ( any pointer type ): same type;
or
Function New ( variant record pointer type; tag fields): same type;
or
Function New ( schema pointer type; discriminants): same type;
or
Function New ( object pointer type; constructor call): same type;
(Under construction.)
Function NewCString ( Const S: String ): CString;
(Under construction.)
(Under construction.)
Operator not ( b1, b2: Boolean ) = result: Boolean;
or
Operator not ( i1, i2: integer type ) = result: integer type;
The keyword `object' is used to declare a new object type:
Type foo = object a: Integer; Constructor Init; Procedure bar ( x: Integer ); virtual; end (* foo *);
(For a longer example, see section Object-orientated Programming.)
GNU Pascal follows the Borland Pascal 7.0 object model.
ISO Pascal does not support Object-orientated programming. There is an ANSI draft for an "Object Pascal" language which is not yet supported by GPC, but planned. The Delphi language, also called "Object Pascal" by Borland, is currently not supported by GPC either.
section Object-orientated Programming, section record.
(Under construction.)
Function odd ( i: Integer ): Boolean;
(Under construction.)
(Under construction.)
(Under construction.)
Operator or ( operand1, operand2: Boolean ) = result: Boolean;
or
Operator or ( operand1, operand2: integer type ) = result: integer type;
or
Procedure or ( Var operand1: integer type; operand2: integer type );
In GNU Pascal, `or' has three built-in meanings:
The logical `or' operator is defined in ISO-7185 Standard Pascal.
According to ISO, you cannot rely on `or' being a short-circuit operator. On the other hand, GPC's default behaviour does not contradict the ISO standard. (See section or_else.) However, since it seems to be a de-facto standard among ISO Pascal compilers to evaluate both operands of `or', GPC switches to `--no-short-circuit' mode if one of the language dialect options selecting ISO Pascal, for instance `--extended-pascal', is given. Use `--short-circuit' to override.
ISO Pascal does not define the bitwise `or' operator; Borland Pascal and Delphi do.
Use of `or' as a "procedure" is a GNU extension.
Var a, b, c: Integer; ... if ( a = 0 ) or ( b = 0 ) then (* logical `or' *) c:= 1 else if a or b = 0 then (* bitwise `or' *) c:= 2 else or ( c, a ); (* same as `c:= c or a' *)
Note the difference between the logical `or' and the bitwise `or': When `a' is 2 and `b' is 4, then `a or b' is 6. Beware: `a or b = 0' happens to mean the same as `( a = 0 ) and ( b = 0 )'. (Note the `and'!)
Since bitwise `or' has a higher priority than the `=' operator, parentheses are needed in `if ( a = 0 ) or ( b = 0 )' because otherwise `0 or b' would be calculated first, and the remainder would cause a parse error.
section and, section xor, section Operators.
`or else' is an alias for the short-circuit logical operator `or_else'.
While `or_else' is defined in ISO-10206 Extended Pascal, `or else' is a GNU Extension.
Var a: Integer; [...] if ( a = 0 ) or else ( 100 div a > 42 ) then (* This is safe. *) [...];
section or_else, section or, section and then.
Operator or_else ( operand1, operand2: Boolean ) = result: Boolean;
The `or_else' short-circuit logical operator performs the same operation as the logical operator `or'. But while the ISO standard does not specify anything about the evaluation of the operands of `or'---they may be evaluated in any order, or not at all---`or_else' has a well-defined behaviour: It evaluates the first operand. If the result is `true', `or_else' returns `true' without evaluating the second operand. If it is `false', the second operand is evaluated and returned.
Since the behaviour described above is the most effective way to implement `or', GPC by default treats `or' and `or_else' exactly the same. If you want, for some reason, to have both operands of `or' evaluated completely, you can specify the `--no-short-circuit' command-line option, but this is not portable. The portable way to have both operands evaluated is to assign both to temporary variables and then use `or'---or `or_else', it does not matter.
ISO-7185 Standard Pascal does not define `or_else'; ISO-10206 Extended Pascal does.
Some people think that the ISO standard requires both operands of `or' to be evaluated. This is false. What the ISO standard does say is that you cannot rely on a certain order of evaluation of the operands of `or'; in particular things like
Var a: Integer; [...] if ( a = 0 ) or ( 100 div a > 42 ) then [...];
can crash according to ISO Pascal, although they cannot crash when compiled with GNU Pascal running in default mode.
If you want to write portable and efficient code in ISO-10206 Extended Pascal, always use `or_else'; never use `or'.
Var a: Integer; [...] if ( a = 0 ) or_else ( 100 div a > 42 ) then (* This is safe. *) [...];
section or else, section or, section and_then.
(Under construction.)
Function ord ( Ch: Char ): Integer;
(Under construction.)
(Under construction.)
(Under construction.)
Var Output: Text;
(Under construction.)
Procedure pack ( Source: unpacked array; FirstElement: index type; Var Dest: packed array );
`packed' is a reserved word. According to ISO-7185 Standard Pascal it can preceed `array' and `record' type definitions to indicate that memory usage should be minimized for variables of this type, possibly at the expense of loss of speed.
As a GNU extension, `packed' can also be applied to section Subrange Types.
The reserved word `packed' is defined in ISO-7185 Standard Pascal.
According to ISO standard, only packed arrays of char with lower bound 1 qualify as strings of fixed length. GNU Pascal neither requires `packed' nor the lower bound of 1 here.
Type MonthInt = packed 1..12; (* needs one byte *) FastMonthInt = 1..12; (* needs four bytes *) FixString10 = packed array [ 1..10 ] of Char; FoxyString10 = array [ 0..9 ] of Char; Flags = packed array [ 1..32 ] of Boolean; (* needs four Bytes *) DateRec = packed record day: 1..31; (* five bits *) month: MonthInt; (* four bits *) year: Integer ( 15 ); (* 15 bits = -16384..16383 *) end (* DateRec *); Dates = array [ 1..1000 ] of DateRec; Var S: FixString10; T: FoxyString10; [...] S:= 'Hello!'; (* blank padded *) writeln ( S ); T:= 'GNU Pascal'; (* GPC extension: this also works. *) writeln ( T );
`DateRec' has 24 bits = 3 bytes in total; `Dates' has 3000 bytes.
section pack, section unpack, section SizeOf, section AlignOf, section BitSizeOf.
(Under construction.)
Procedure Page ( Var F: Text );
or
Procedure Page;
(Under construction.)
Type pAnsiChar = ^AnsiChar;
Function ParamCount: Integer;
`ParamCount' returns the number of command-line arguments given to the program. `ParamCount' returns 0 if no arguments have been given to the program; the name of the program as an implicit argument is not counted.
`ParamCount' is a Borland Pascal extension.
Program Test; Var i: Integer; begin writeln ( 'You have invoked this program with ', ParamCount, ' arguments.' ); writeln ( 'These are:' ); for i:= 1 to ParamCount do writeln ( ParamStr ( i ) ); end.
section ParamStr.
(Under construction.)
Function ParamStr ( ParmNumber: Integer ): String;
(Under construction.)
Type pChar = ^Char;
or
Type pChar = CString;
(Under construction.)
(Under construction.)
Function polar ( rho, phi: Real ): Complex;
(Under construction.)
Function pos ( SearchPattern, Source: String ): Integer;
(Under construction.)
Function Position ( Var F: typed file );
(Under construction.)
Operator pow ( base: Real; exponent: Integer ) = power: Real;
or
Operator pow ( base: Complex; exponent: Integer ) = power: Complex;
Function pred ( i: ordinal type ): ordinal type;
or
Function pred ( i: ordinal type; j: Integer ): ordinal type;
or, with extended syntax (`--extended-syntax' or `(*$X+*)'),
Function pred ( p: pointer type ): pointer type;
or
Function pred ( p: pointer type; j: Integer ): pointer type;
Returns the predecessor of the ordinal type value `i', or, if the second argument `j' is given, its `j'th predecessor. For integer values `i', this is `i - 1' (or `i - j'). (No, `pred' does not work faster than plain subtraction. Both are optimized to a single machine instruction or even expanded by the compiler, if possible.)
If extended syntax is on, the argument may also be a pointer value. In this case, the address is decremented by the size of the variable pointed to, or, if `j' is given, by `j' times the size of the variable pointed to. If `p' points to an element of an array, the returned pointer will point to the (`j'th) previous element of the array.
The `pred' function is defined in ISO-7185 Standard Pascal. The optional second parameter is defined in ISO-10206 Extended Pascal. Application of `pred' to pointers is defined in Borland Pascal. The combination of the second argument with application to pointers is a GNU extension.
Program PredTest; Type Metasyntactical = ( foo, bar, baz ); Var m: Metasyntactical; c: Char; a: array [ 1..7 ] of Integer; p: ^Integer; begin m:= pred ( bar ); (* foo *) c:= pred ( 'Z', 2 ); (* 'X' *) a [ 1 ]:= 42; a [ 4 ]:= pred ( a [ 1 ] ); (* 41 *) a [ 5 ]:= pred ( a [ 4 ], 3 ); (* 38 *) (*$X+*) p:= @a [ 5 ]; p:= pred ( p ); (* now points to `a [ 4 ]' *) p:= pred ( p, 3 ); (* now points to `a [ 1 ]' *) end.
section succ, section dec, section Pointer Arithmetics.
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
Procedure Put ( Var F: typed file );
(Under construction.)
Function Re ( z: Complex ): Real;
(Under construction.)
Procedure read ( Var F: typed file; variable );
or
Procedure read ( Var F: Text; variables );
or
Procedure read ( variables );
(Under construction.)
Procedure readln ( Var F: Text; variables );
or
Procedure readln ( variables );
(Under construction.)
Procedure ReadStr ( Const S: String; variables );
(Under construction.)
The reserved word `record' starts the definition of a new record type. The syntax is
foo = record field declarations end (* foo *);
or, with a variant part,
foo = record field declarations case bar: variant type of selector: ( field declarations ); selector: ( field declarations ); ... end (* foo *);
or, without a variant selector field,
foo = record field declarations case variant type of selector: ( field declarations ); selector: ( field declarations ); ... end (* foo *);
Records can be `packed' to save memory usage at the expense of speed.
The variants of a variant record share one location in memory (inside the record) and thus can be used to emulate type casting without violating ISO-7185 Standard Pascal.
The reserved word `record' and record types are defined in ISO-7185 Standard Pascal.
According to ISO Pascal, the variant type must be an identifier. GNU Pascal, like UCSD and Borland Pascal, also allows a subrange here.
Type fooPtr = ^foo; foo = record bar: Integer; nextFoo: fooPtr; case choice: 1..3 of 1: ( a: Integer ); (* These three choices share *) 2: ( b: Real ); (* one location in memory. *) 3: ( c: Char; d: Boolean ); end (* foo *); smallFoo = packed record b: 0..3; a: Integer ( 5 ); r: Boolean; end (* smallFoo *); (* needs 1 byte *) Var f: foo; [...] f.b:= 3.14; writeln ( f.a ); (* yields some strange number which is part of the *) (* internal representation of the real number `f.b'. *)
section packed, section array, section object.
(Under construction.)
Procedure Release ( P: Pointer );
(Under construction.)
Procedure Rename ( Var F: any file; NewName: String );
(Under construction.)
(Under construction.)
Procedure reset ( Var F: any file );
or
Procedure reset ( Var F: any file; FileName: String );
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
Procedure rewrite ( Var F: any file );
or
Procedure rewrite ( Var F: any file; FileName: String );
(Under construction.)
Procedure RmDir ( Directory: String );
(Under construction.)
Function round ( x: Real ): Integer;
(Under construction.)
Procedure RunError ( ErrorCode: Integer );
(Under construction.)
Procedure Seek ( Var F: typed file; NewPosition: Integer );
(Under construction.)
Procedure SeekRead ( Var F: typed file; NewPosition: Integer );
(Under construction.)
Procedure SeekUpdate ( Var F: typed file; NewPosition: Integer );
(Under construction.)
Procedure SeekWrite ( Var F: typed file; NewPosition: Integer );
(Under construction.)
(Under construction.)
Procedure SetLength ( Var S: String; NewLength: Integer );
`SetLength' explicitly assigns a new length `NewLength' to the
string parameter S
. The contents of the string is not changed;
if the operation increases the length of the string, the characters appended
at the end are undefined.
If you want to use `SetLength', please enable "extended syntax" (`--extended-syntax' or `(*$X+*)').
`SetLength' is a Borland Delphi 2.0 extension.
Program TestSetLength; (*$X+*) (* Enable "dangerous" features *) Var S: String ( 26 ); begin S:= 'Hello, world!'; SetLength ( S, length ( 'Hello' ) ); writeln ( S ); (* 'Hello' *) SetLength ( S, 26 ); writeln ( S ); (* 'Hello, world!(%$@ާ"!"ާ$ާ"$' *) (* undefined characters ^^^^^^^^^^^^^ *) SetLength ( S, 42 ); (* The overflow is *not* (yet) detected *) writeln ( S ); (* This might cause a runtime error. *) end.
section length, section String, section SetType.
Procedure SetType ( Var SomeObject; VMT: Pointer );
The procedure `SetType' explicitly assigns a value to the implicit VMT field of an object. This is normally done implicitly when a constructor is called.
You can use this to write a polymorphic I/O routine which reads an object from a file. In this case, you cannot reasonably use `New' to allocate the storage, but you `GetMem' it and initialize the object manually using `SetType' before calling the constructor explicitly.
This is a dangerous feature which yields a warning unless `(*$X+*)' is given.
`SetType' is a GNU extension.
(*$X+*) Type BasePtr = ^BaseObj; BaseObj = object Constructor Load; end (* BaseObj *) [Successor objects ...] [...] Function GetObject = Result: BasePtr; Var Size: Cardinal; VMT: Pointer; begin (* GetObject *) [Read the size of the object from some file and store it in `Size'.] GetMem ( Result, Size ); [Read some ID from some file and look up the `VMT' from some table.] SetType ( Result^, VMT ); (* Now the object is ready, and the constructor can be called. *) [Look up the correct constructor from some table and call it.] end (* GetObject *);
section TypeOf, section Object-orientated Programming.
`ShortCard' is an unsigned integer type which is not larger than `Cardinal'. On most platforms it is 16 bits wide and thus has a range of `0..65535'.
`ShortCard' in GNU Pascal is compatible to `short unsigned int' in GNU C.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `ShortCard'. (However see section Subrange Types.)
section Integer Types, section Subrange Types.
`ShortInt' is a signed integer type which is not larger than `Integer'. On most platforms it is 16 bits wide and thus has a range of `-32768..32767'.
`ShortInt' in GNU Pascal is compatible to `short int' in GNU C.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `ShortInt'. (However see section Subrange Types.)
`ShortInt' in GNU Pascal corresponds to `Integer' in Borland Pascal and Delphi 1.0. Both Borland languages also define `ShortInt', but it is an 8-bit signed integer type there (`ByteInt' in GNU Pascal).
section Integer Types, section Subrange Types.
(Under construction.)
`ShortWord' is an unsigned integer type which is not larger than `Word'. On most platforms it is 16 bits wide and thus has a range of of `0..65535'. It is the same as section ShortCard.
`ShortWord' in GNU Pascal is compatible to `short unsigned int' in GNU C.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `ShortWord'. (However see section Subrange Types.)
`ShortWord' in GNU Pascal essentially corresponds to `Word' in Borland Pascal and Delphi where it is a 16-bit unsigned integer type.
section Integer Types, section Subrange Types.
(Under construction.)
Type Single = ShortReal;
Operator shl ( operand1, operand2: integer type ) = result: integer type;
or
Procedure shl ( Var operand1: integer type; operand2: integer type );
In GNU Pascal, `shl' has two built-in meanings:
ISO Pascal does not define the `shl' operator; Borland Pascal and Delphi do.
Use of `shl' as a "procedure" is a GNU extension.
Var a: Integer; ... a:= 1 shl 7; (* yields 128 = 2 pow 7 *) shl ( a, 4 ); (* same as `a:= a shl 4' *)
section shr, section Operators.
Operator shr ( operand1, operand2: integer type ) = result: integer type;
or
Procedure shr ( Var operand1: integer type; operand2: integer type );
In GNU Pascal, `shr' has two built-in meanings:
ISO Pascal does not define the bitwise `shr' operator; Borland Pascal and Delphi do.
Unlike the Borland compilers, GNU Pascal cares about the signedness of the first operand: If a signed integer with a negative value is shifted right, "one" bits are filled in from the left.
Use of `shr' as a "procedure" is a GNU extension.
Var a: Integer; ... a:= 1024 shr 4; (* yields 64 *) a:= -127 shr 4; (* yields -7 *) shr ( a, 2 ); (* same as `a:= a shr 2' *)
section shl, section Operators.
(Under construction.)
Function sin ( x: Real ): Real;
or
Function sin ( z: Complex ): Complex;
Function SizeOf ( Var x ): Integer;
Returns the size of a type or variable in bytes.
ISO Pascal does not define `SizeOf'; UCSD and Borland Pascal do.
Var a: Integer; b: array [ 1..8 ] of Char; ... writeln ( SizeOf ( a ) ); (* Size of an `Integer'; usually 4 bytes. *) writeln ( SizeOf ( b ) ); (* Size of eight `Char's; usually 8 bytes. *)
section BitSizeOf, section AlignOf, section TypeOf.
`SmallInt' is a signed integer type which is not larger than `Integer'. On most platforms it is 16 bits wide and thus has a range of `-32768..32767'. It is the same as `ShortInt' (see section ShortInt).
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `SmallInt'. (However see section Subrange Types.)
`SmallInt' also appears in Delphi 2.0. This compatibility is the reason why GPC supports the synonym `SmallInt' for `ShortInt'.
section Integer Types, section Subrange Types.
Function sqr ( i: integer type ): integer type;
or
Function sqr ( x: real type ): real type;
or
Function sqr ( z: complex type ): complex type;
Returns the square of the argument:
Function sqr ( x: some type ): some type; begin (* sqr *) sqr:= x * x; (* or: x pow 2 *) end (* sqr *);
The function `sqr' is defined in ISO-7185 Standard Pascal; its application to complex values is defined in ISO-10206 Extended Pascal.
Program TestSqr; Var i: Complex; begin i:= cmplx ( 0, 1 ); writeln ( Re ( sqr ( i ) : 0 : 3 ); (* yields -1.000 *) end.
section pow, section sqrt, section abs, section Operators.
Function sqrt ( x: real type ): real type;
or
Function sqrt ( z: complex type ): complex type;
Returns the positive square root of the argument.
For real arguments, it is an error if the argument is negative.
For complex arguments, `sqrt' returns the principal value of the root of the argument, i.e. the root with positive real part, or, if the real part is zero, that one with positive imaginary part.
The function `sqrt' is defined in ISO-7185 Standard Pascal; its application to complex values is defined in ISO-10206 Extended Pascal.
Program TestSqrt; Var m1: Complex; begin m1:= cmplx ( -1, 0 ); (* -1 *) writeln ( Re ( sqrt ( m1 ) ) : 6 : 3, Im ( sqrt ( m1 ) ) : 6 : 3 ); (* yields 1.000 -1.000, i.e. the imaginary unit, i *) end.
section pow, section sqr, section Operators.
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
Var StdErr: Text;
(Under construction.)
Procedure Str ( x: integer or real; Var Dest: String );
or
Procedure Str ( x: integer or real : field width; Var Dest: String );
or
Procedure Str ( x: Real : field width : precision; Var Dest: String );
or
Procedure Str ( repeated constructs as described above; Var Dest: String );
(Under construction.)
Function StrPCopy ( Dest: CString; Const Source: String ): CString;
(Under construction.)
(Under construction.)
Function String2CString ( Const S: String ): CString;
(Under construction.)
Function SubStr ( S: String; FirstChar: Integer ): String;
or
Function SubStr ( S: String; FirstChar, Count: Integer ): String;
Function succ ( i: ordinal type ): ordinal type;
or
Function succ ( i: ordinal type; j: Integer ): ordinal type;
or, with extended syntax (`--extended-syntax' or `(*$X+*)'),
Function succ ( p: pointer type ): pointer type;
or
Function succ ( p: pointer type; j: Integer ): pointer type;
Returns the successor of the ordinal type value `i', or, if the second argument `j' is given, its `j'th successor. For integer values `i', this is `i + 1' (or `i + j'). (No, `succ' does not work faster than plain addition. Both are optimized to a single machine instruction or even expanded by the compiler, if possible.)
If extended syntax is on, the argument may also be a pointer value. In this case, the address is incremented by the size of the variable pointed to, or, if `j' is given, by `j' times the size of the variable pointed to. If `p' points to an element of an array, the returned pointer will point to the (`j'th) next element of the array.
The `succ' function is defined in ISO-7185 Standard Pascal. The optional second parameter is defined in ISO-10206 Extended Pascal. Application of `succ' to pointers is defined in Borland Pascal. The combination of the second argument with application to pointers is a GNU extension.
Program SuccTest; Type Metasyntactical = ( foo, bar, baz ); Var m: Metasyntactical; c: Char; a: array [ 1..7 ] of Integer; p: ^Integer; begin m:= succ ( foo ); (* bar *) c:= succ ( 'A', 4 ); (* 'E' *) a [ 1 ]:= 42; a [ 2 ]:= succ ( a [ 1 ] ); (* 43 *) a [ 5 ]:= succ ( a [ 2 ], 7 ); (* 50 *) (*$X+*) p:= @a [ 1 ]; p:= succ ( p ); (* now points to `a [ 2 ]' *) p:= succ ( p, 3 ); (* now points to `a [ 5 ]' *) end.
section pred, section inc, section Pointer Arithmetics.
(Under construction.)
(Under construction.)
(Under construction.)
Function Time ( T: TimeStamp ): packed array [ 1..time length ] of Char;
(Under construction.)
Type TimeStamp = record DateValid, TimeValid: Boolean; Year: Integer; Month: 1..12; Day: 1..31; Hour: 0..23; Minute, Second: 0..59; MicroSecond: Integer; end (* TimeStamp *);
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
Function Trim ( S: String ): String;
(Under construction.)
(Under construction.)
Function trunc ( x: Real ): Integer;
(Under construction.)
Procedure Truncate ( Var F: any file );
(Under construction.)
Function TypeOf ( Var x ): Pointer;
Returns a pointer to the VMT of an object type or variable. This pointer can be used to identify the type of an object.
ISO Pascal does not define `TypeOf', Borland Pascal does.
Type fooPtr = ^foo; barPtr = ^bar; foo = object (* Has a VMT, though it doesn't *) x: Integer; (* contain virtual methods. *) Constructor Init; end (* foo *); bar = object ( foo ) y: Integer; end (* bar *); Var MyFoo: fooPtr; [...] MyFoo:= New ( barPtr, Init ); if TypeOf ( MyFoo^ ) = TypeOf ( bar ) then (* true *) writeln ( 'OK' );
section BitSizeOf, section AlignOf, section TypeOf, section SetType, section Object-orientated Programming.
(Under construction.)
Procedure UnBind ( Var F: any file );
(Under construction.)
(Under construction.)
Procedure unpack ( Source: packed array; Var Dest: unpacked array; FirstElement: index type );
(Under construction.)
(Under construction.)
Function UpCase ( Ch: Char ): Char;
(Under construction.)
Procedure update ( Var F: any file );
or
Procedure update ( Var F: any file; FileName: String );
The reserved word `uses' in the import part of a program makes the program import an interface. The syntax is
Program foo; uses bar1, bar2 in 'baz.pas', bar3; [...]
or, in a Unit,
Unit Bar3; Interface uses bar1, bar2 in 'baz.pas'; [...]
The `in' above tells GPC to look for the `Unit' in the specified file; otherwise the file name is derived from the name of the interface by adding first `.p', then `.pas'.
There must be at most one import part in a program.
In a Unit, there is only one import part in the interface part; GPC currently does not support a second import part in the implementation part.
The imported interface needn't be an UCSD/Borland Pascal Unit, it may be an interface exported by an Extended Pascal Module as well.
ISO Pascal does not define `uses' and Units in general. UCSD and Borland Pascal do, but without the `in' extension. Delphi supports `uses' like described above.
section Unit, section Module, section import.
(Under construction.)
Procedure Val ( Const Source: String; Var x: integer or real );
or
Procedure Val ( Const Source: String; Var x: integer or real; Var ErrorCode: Integer );
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
`Word' is the "natural" unsigned integer type in GNU Pascal. On most platforms it is 32 bits wide and thus has a range of `0..4294967295'. It is the same as section Cardinal, introduced for compatibility with other Pascal compilers.
As an extension, GPC allows to use `Word' as a pseudo-schema to produce types with a specified size in bits; for example
Type Word16 = Cardinal ( 16 );
defines an unsigned integer type with 16 bits. The same mechanism works for `Cardinal' and `Integer', too.
`Word' in GNU Pascal is compatible to `unsigned int' in GNU C.
There are lots of other integer types in GPC, see section Integer Types.
ISO Pascal does not define `Cardinal'. (However see section Subrange Types.)
The `Word' type appears in Borland Pascal and Delphi, too, where it is a 16-bit unsigned integer type.
section Integer Types, section Subrange Types.
(Under construction.)
Procedure write ( Var F: typed file; variable );
or
Procedure write ( Var F: Text; values and format specifications );
or
Procedure write ( values and format specifications );
(Under construction.)
Procedure writeln ( Var F: Text; values and format specifications );
or
Procedure writeln ( values and format specifications );
(Under construction.)
Procedure WriteStr ( Var Dest: String; values and format specifications );
Operator xor ( operand1, operand2: Boolean ) = result: Boolean;
or
Operator xor ( operand1, operand2: integer type ) = result: integer type;
or
Procedure xor ( Var operand1: integer type; operand2: integer type );
In GNU Pascal, `xor' has three built-in meanings:
ISO Pascal does not define the `xor' operator; Borland Pascal and Delphi do.
Use of `xor' as a "procedure" is a GNU extension.
Var a, b, c: Integer; ... if ( a = 0 ) xor ( b = 0 ) then c:= 1 (* happens if either `a' or `b' is zero, *) (* but not if both are zero or both nonzero *) else if a xor b = 0 then (* bitwise `xor': `a' must be the bitwise *) c:= 2 (* complement of `b' to fullfill this *) else xor ( c, a ); (* same as `c:= c xor a' *)
section and, section or, section Operators.