This chapter is still under development. All identifiers are listed, but not all with explanations.
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.
`absolute' is a Borland Pascal extension.
Borland Pascal 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 Pascal 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 addr ( Const Foo ): Pointer;
`addr' returns the address of its argument. It is equivalent to the address operator and provided for compatibility with Borland Pascal which in turn implements it for backward-compatibility with Turbo Pascal.
`addr' is a Borland Pascal extension.
Var Foo: ^Integer; Bar: Integer; [...] Foo:= addr ( Bar ); (* Let `Foo' point to `Bar'. *) Foo^:= 42; (* Change the value of `Bar' to 42 *)
section Operators.
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.
Use of `and' as a bitwise operator for integers is a Borland Pascal extension.
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 efficient 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 must assign both to temporary variables and then use `and'---or `and_then', it does not matter.
`and_then' is an ISO-10206 Extended Pascal extension.
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.
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.
`AnsiChar' is a Borland Delphi extension.
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; [ name: String; ] [ blocksize: Cardinal ] );
`Append' opens a file for writing. If the file does not exist, it is created. If it does exist, the file pointer is positioned after the last element.
Like `rewrite' and `reset' do, `append' accepts an optional second and third parameter for the name of the file in the filesystem and, for untyped files, the block size of the file. (For details, see section rewrite.)
`append' is a Borland Pascal extension. ISO-10206 Extended Pascal has section extend instead.
Var Sample: Text; [...] Assign ( Sample, 'sample.txt' ); rewrite ( Sample ); writeln ( Sample, 'Hello, World!' ); (* `sample.txt' now has one line *) close ( Sample ); [...] append ( Sample ); writeln ( Sample, 'Hello again!' ); (* `sample.txt' now has two lines *) close ( Sample );
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'.
`Arg' is an ISO-10206 Extended Pascal extension.
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.)
See `ftp://agnes.dida.physik.uni-essen.de/gnu-pascal/contrib/gpcasm.zip'.
`asm', as implemented in GPC, is a GNU extension. It is mostly compatible with GCC's `asm', but not compatible to that of Borland Pascal.
Procedure/Function header; asmname name;
The `asmname' directive, like the `external' directive, declares a procedure or function that is defined externally. The external name of the routine is given explicitly as a case-sensitive string constant. This is useful when interfacing with libraries written in other languages.
`asmname' is a GNU Pascal extension.
Function XOpenDisplay ( DisplayName: CString ): Pointer; asmname 'XOpenDisplay'; [...] MyDisplay:= XOpenDisplay ( 'MyDisplay' );
section C, section C_Language, section external.
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.)
Function assigned ( p: Pointer ): Boolean;
or
Function assigned ( p: procedural type ): Boolean;
The `assigned' function returns `true' if the pointer parameter or the address of the procedural parameter is not `Nil'; it returns `false' if it is `Nil'.
`assigned' is a Borland Pascal extension.
(Under construction.)
`attribute' is a GNU Pascal extension.
(Under construction.)
(Under construction.)
Procedure Bind ( Var F: any file; B: BindingType );
`Bind' is an ISO-10206 Extended Pascal extension.
(Under construction.)
`bindable' is an ISO-10206 Extended Pascal extension.
(Under construction.)
Function Binding ( F: any file ): BindingType;
`Binding' is an ISO-10206 Extended Pascal extension.
(Under construction.)
UnixTimeType = LongInt; GPC_BindingType = {@@packed} record Bound : Boolean; Force : Boolean; { Can be set to allow binding to non-writable files or directories } Extensions_Valid : Boolean; Readable : Boolean; Writable : Boolean; Executable : Boolean; Existing : Boolean; { Binding points to an existing file } Directory : Boolean; { Binding points to an existing directory; Existing is False then } Size : LongInt; { Number of elements or -1 } AccessTime, { Time of last access } ModificationTime, { Time of last modification } ChangeTime : UnixTimeType; { Time of last change } User, { User ID of owner } Group, { Group ID of owner } Mode, { Protection mode, cf. ChMod } INode : Integer; { Unix INode number } CFile : CFilePtr; { allows binding a Pascal file to a C file } Name : String (Binding_Name_Length) end;
`BindingType' is an ISO-10206 Extended Pascal extension.
Function BitSizeOf ( Var x ): SizeType;
Returns the size of a type or variable in bits.
`BitSizeOf' is a GNU Pascal 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 );
`BlockRead' is an UCSD Pascal extension.
(Under construction.)
Procedure BlockWrite ( Var F: File; Const Buffer; Blocks: Integer );
or
Procedure BlockWrite ( Var F: File; Const Buffer; Blocks: Integer; Var BlocksWritten: Integer );
`BlockWrite' is an UCSD Pascal extension.
(Under construction.)
`Boolean' is defined in ISO-7185 Standard Pascal and supported by all known Pascal variants.
`break' (simple statement)
The `break' statement causes a loop to exit. It is equivalent to a `goto' to the first instruction that follows the body of the loop.
`break' is a Borland Pascal extension.
Var i: Integer; [...] i:= 1; while i <= 6 do begin inc ( i ); writeln ( 'bla' ); if i > 3 then break; end (* while *);
yields
bla bla bla
section continue, section exit, section return, section goto.
`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.
`Byte' is a Borland Pascal extension. (For something equivalent in ISO Pascal, see section Subrange Types.)
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.
`ByteCard' is a GNU Pascal extension.
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.
`ByteInt' is a GNU Pascal extension.
`ByteInt' in GNU Pascal corresponds to section ShortInt in Borland Pascal.
section Integer Types, section Subrange Types.
(Under construction.)
(Under construction.)
(Under construction.)
Function Card ( S: any set ): Integer;
`Card' returns the number of elements in the set S.
`Card' is an ISO-10206 Extended Pascal extension.
`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.
`Cardinal' is not defined in ISO Pascal, but several Pascal compilers support it as an extension. In Borland Delphi, for instance, it is an unsigned 16-bit in version 1.0, an unsigned 31-bit integer from version 2.0 on, and an unsigned 32-bit integer from version 4.0 on.
section Integer Types, section Subrange Types.
(Under construction.)
`case' is defined in ISO-7185 Standard Pascal and supported by all known Pascal variants.
(Under construction.)
`Char' is defined in ISO-7185 Standard Pascal and supported by all known Pascal variants.
(Under construction.)
Procedure ChDir ( Directory: String );
`ChDir' is a Borland Pascal extension.
(Under construction.)
Function chr ( AsciiCode: Integer ): Char;
`chr' is defined in ISO-7185 Standard Pascal and supported by all known Pascal variants.
(Under construction.)
Procedure Close ( Var F: any file );
(Under construction.)
Function cmplx ( RealPart, ImaginaryPart: Real ): Complex;
`cmplx' is an ISO-10206 Extended Pascal extension.
`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.
`Comp' is a Borland Pascal extension.
In some contexts, Borland Pascal treats `Comp' as a "real" type--this behaviour is not supported by GPC.
section Integer Types, section Subrange Types.
(Under construction.)
`Complex' is an ISO-10206 Extended Pascal extension.
(Under construction.)
Function Concat ( S1, S2: String ): String;
or
Function Concat ( S1, S2, S3: String ): String;
or
...
`Concat' is an UCSD Pascal extension.
(Under construction.)
Function conjugate ( z: Complex ): Complex;
`conjugate' is an ISO-10206 Extended Pascal extension.
(Under construction.)
`Const' is defined in ISO-7185 Standard Pascal and supported by all known Pascal variants.
(Under construction.)
`Constructor' is a Borland Pascal extension.
`continue' (simple statement)
The `continue' statement causes a loop to execute the next turn. It is equivalent to a `goto' to the end of the block that is the body of the loop.
`continue' is a Borland Pascal extension.
Var i: Integer; [...] i:= 1; while i <= 6 do begin inc ( i ); write ( 'bla' ); if i <= 3 then continue; writeln; end (* while *);
yields
blablabla bla bla bla
section break, section exit, section return, section goto.
Function Copy ( S: String; FirstChar, Count: Integer ): String;
or
Function Copy ( S: String; FirstChar: Integer ): String;
`Copy' returns a sub-string of S starting with the character at position FirstChar. If Count is given, such many characters will be copied into the sub-string. If Count is omitted, the sub-string will will range to the end of S.
If `Count' is too large for the sub-string to fit in S, the result will be truncated at the end of S. If `FirstChar' exceeds the length of S, the empty string will be returned. (For a function which does not truncate but triggers a runtime error instead, see section SubStr.)
Please note that GPC's strings may be longer than 255 characters. If you want to isolate the second half of a string S starting with the third character, use `Copy ( S, 3)' instead of `Copy ( S, 3, 255 )'.
`Copy' is an UCSD Pascal extension. The possibility to omit the third parameter is a GNU Pascal extension.
Var S: String ( 42 ); [...] S:= 'Hello'; writeln ( Copy ( S, 2, 3 ) ); (* yields "ell" *) writeln ( Copy ( S, 3 ) ); (* yields "llo" *) writeln ( Copy ( S, 4, 7 ) ); (* yields "lo" *) writeln ( Copy ( S, 42 ) ); (* yields the empty string *)
section SubStr, String slice access.
(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 );
`Dec' is a Borland Pascal extension.
section inc, `pred'.
(Under construction.)
(Under construction.)
Procedure DefineSize ( Var F: any file; NewSize: Integer );
(Under construction.)
Procedure Delete ( Var S: String; FirstChar, Count: Integer );
`Delete' is a UCSD Pascal extension.
(Under construction.)
`Destructor' is a Borland Pascal extension.
(Under construction.)
Dispose ( PointerVar: Pointer );
or
Dispose ( PointerVar: Pointer; tag field values );
or
Dispose ( ObjectPointerVar: Pointer; destructor call );
`Dispose' is defined in ISO-7185 Standard Pascal and supported by most known Pascal variants, but not by UCSD Pascal. Its use for objects is a Borland Pascal extension.
(Under construction.)
Operator div ( p, q: Integer ) = r: Integer;
`div' is defined in ISO-7185 Standard Pascal and supported by all known Pascal variants.
for ... do statement
or
while ... do statement
or
with ... do statement
or
to begin do statement
or
to end do statement
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 ISO-7185 Standard Pascal and supported by all known Pascal variants.
See references.
section for, section while, section with, section to begin, section to end.
(Under construction.)
Type Double = Real;
`Double' is a synonym for the `Real' data type and supported for compatibility with other compilers.
`Double' is a Borland Pascal extension.
Var A: Double; (* There is nothing special with `Double'. *) B: Real; [...] A:= pi; A:= B;
for variable := value1 downto value2 do statement
The `downto' reserved word is used in combination with `for' to build a `for' loop.
`downto' is defined in ISO-7185 Standard Pascal and supported by all known Pascal variants.
See section for.
section for.
(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.)
`far' is a Borland Pascal extension.
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.
`FreeMem' is a Borland Pascal extension. `FreeMem' with only one parameter is a GNU Pascal 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.
`GetMem' is a Borland Pascal extension. The use of `GetMem' as a function is a GNU Pascal 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 );
`GetTimeStamp' is an ISO-10206 Extended Pascal extension.
(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.
`import' and Modules in general are an ISO-10206 Extended Pascal extension.
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.
`LongCard' is a GNU Pascal extension.
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.
`LongInt' is a Borland Pascal extension. Borland Pascal defines `LongInt' as a 32-bit signed integer type (section Integer in GNU Pascal).
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.
`LongestCard' is a GNU Pascal extension.
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.
`LongestInt' is a GNU Pascal extension.
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.
`LongestWord' is a GNU Pascal extension.
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.
`LongWord' is a GNU Pascal extension.
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.
`MedCard' is a GNU Pascal extension.
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.
`MedInt' is a GNU Pascal extension.
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.
`MedWord' is a GNU Pascal extension.
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.)
`near' is a Borland Pascal extension.
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;
(Under construction.)
Var NULL: Void absolute 0;
Variable at address Nil
.
Delphi
section Nil.
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.
Use of `or' as a bitwise operator for integers is a Borland Pascal extension.
Use of `or' as a "procedure" is a GNU Pascal 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 efficient 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 must assign both to temporary variables and then use `or'---or `or_else', it does not matter.
`or_else' is an ISO-10206 Extended Pascal extension.
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.
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;
Note: If you are using the MS-DOS (DJGPP) or MS-Windows (mingw32) version of GPC and are getting unexpected results from `ParamStr', please see the section "Command-line Arguments Handling in DJGPP" of the DJGPP FAQ list.
(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.)
GPC currently accepts but ignores the `private' directive in object type declarations.
section protected, section public, section published.
(Under construction.)
(Under construction.)
(Under construction.)
The Extended Pascal meaning of `protected' is supported by GPC.
GPC currently accepts but ignores the `protected' directive in object type declarations.
Extended Pascal and Borland Pascal, but with different meanings.
section Const, section import, section private, section public, section published.
(Under construction.)
(Under construction.)
(Under construction.)
(Under construction.)
GPC currently accepts but ignores the `public' directive in object type declarations.
section private, section protected, section published.
(Under construction.)
GPC currently accepts but ignores the `published' directive in object type declarations.
section private, section protected, section public.
(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 SetFileTime ( Var F: any file; time: UnixTimeType );
`SetFileTime' is a GNU extension.
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.
`ShortCard' is a GNU Pascal extension.
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.
`ShortInt' is a Borland Pascal extension. In Borland Pascal, `ShortInt' is an 8-bit signed integer type (`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.
`ShortWord' is a GNU Pascal extension.
`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:
`shl' is a Borland Pascal extension.
Use of `shl' as a "procedure" is a GNU Pascal 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:
`shr' is a Borland Pascal extension.
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 ): SizeType;
Returns the size of a type or variable in bytes.
`SizeOf' is an UCSD Pascal extension.
Var a: Integer; b: array [ 1..8 ] of Char; ... writeln ( SizeOf ( a ) ); (* Size of an `Integer'; often 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.
`SmallInt' is a Delphi 2.0 extension.
section 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.)
Var StdErr: Text;
The `StdErr' variable is connected to the standard error device. To report errors, you should prefer `writeln ( StdErr, 'everything wrong' )' over `writeln ( 'everything wrong' )'.
`StdErr' is a GNU Pascal extension.
Var Denominator: Integer; ... readln ( Denominator ); if Denominator = 0 then writeln ( StdErr, ParamStr ( 0 ), ': division by zero' ) else writeln ( '1 / ', Denominator, ' = ', 1 / Denominator )
section StandardError, section Output, section Input.
(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 );
`Str' is an UCSD Pascal extension, generalized by Borland Pascal. The possibility to handle more than one variable with one call to `Str' is a GNU Pascal extension.
ISO-10206 Extended Pascal defines `WriteStr' instead of `Str'.
section WriteStr.
(Under construction.)
Function CStringCopyString ( Dest: CString; Const Source: String ): CString;
(Under construction.)
(Under construction.)
Function String2CString ( Const S: String ): CString;
Function SubStr ( S: String; FirstChar: Integer ): String;
or
Function SubStr ( S: String; FirstChar, Count: Integer ): String;
`SubStr' returns a sub-string of S starting with the character at position FirstChar. If Count is given, such many characters will be copied into the sub-string. If Count is omitted, the sub-string will will range to the end of S.
If `Count' is too large for the sub-string to fit in S or if `FirstChar' exceeds the length of S, `SubStr' triggers a runtime error. (For a function returning the empty string instead, see section Copy.)
`SubStr' is a ISO 10206 Extended Pascal extension.
Var S: String ( 42 ); [...] S:= 'Hello'; writeln ( SubStr ( S, 2, 3 ) ); (* yields "ell" *) writeln ( SubStr ( S, 3 ) ); (* yields "llo" *) writeln ( SubStr ( S, 4, 7 ) ); (* yields a runtime error *) writeln ( SubStr ( S, 42 ) ); (* yields a runtime error *)
section Copy, String slice access.
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.
Go to the first, previous, next, last section, table of contents.