GNU Pascal
From Compsci.ca Wiki
This page is a direct extract from the GPC Manual. If you want to browse the manual, you can start at the top of the manual or at the counterpart of this page within the manual.
The GNU Pascal Compiler (GPC) is, as the name says, the Pascal compiler of the GNU family (http://www.gnu.org/software/gcc/). This means:
- GPC is a 32/64 bit compiler,
- does not have limits like the 64 kB or 640 kB limit known from certain operating systems – even on those systems –,
- runs on all operating systems supported by GNU C, including
- GNU Hurd,
- Linux on Intel, AMD64, Sparc, Alpha, S390, and all other supported types of hardware,
- the BSD family: FreeBSD, NetBSD, OpenBSD,
- DOS with 32 bits, using DJGPP or EMX,
- MS-Windows 9x/NT, using CygWin or mingw or MSYS,
- OS/2 with EMX,
- Mac OS X,
- MIPS-SGI-IRIX,
- Alpha-DEC-OSF,
- Sparc-Sun-Solaris,
- HP/UX,
- can act as a native or as a cross compiler between all supported systems,
- produces highly optimized code for all these systems,
- is Free Software (Open-Source Software) according to the GNU General Public License,
- is compatible to other GNU languages and tools such as GNU C and the GNU debugger.
- ISO 7185 Pascal (see Resources),
- most of ISO 10206 Extended Pascal,
- Borland Pascal 7.0,
- parts of Borland Delphi, Mac Pascal and Pascal-SC (PXSC).
- From Standard Pascal: Many popular Pascal compilers claim to extend Standard Pascal but miss these important features.
- Conformant array parameters – the standardized and comfortable way to pass arrays of varying size to procedures and functions.
- Passing local procedures as procedural parameters – with full access to all variables of the “parent” procedure.
- Automatic file buffers and standard Get and Put procedures. Read ahead from files without temporary variables. This allows you, for instance, to validate numeric input from text files before reading without conversion through strings.
- True packed records and arrays. Pack 8 Booleans into 1 byte.
- Internal files. You don't have to worry about creating temporary file names and erasing the files later.
- Global goto. (Yes, goto has its place when it is not restricted to the current routine.)
- Automatically set discriminants of variant records in New.
- Sets of arbitrary size. [Example]
- From Extended Pascal:
- Strings of arbitrary length.
- ReadStr and WriteStr. Read from and write to strings with the full comfort of ReadLn/WriteLn.
- System-independent date/time routines.
- Set member iteration: for Ch in ['A' .. 'Z', 'a' .. 'z'] do ...
- Set extensions (symmetric difference, Card)
- Generalized Succ and Pred functions (foo := Succ (bar, 5);).
- Complex numbers.
- Exponentiation operators (pow and **) for real and complex numbers.
- Initialized variables.
- Functions can return array or record values.
- Result variables.
- Modules.
- Non-decimal numbers in base 2 through 36: base#number.
- MinReal, MaxReal, EpsReal, MaxChar constants.
- Schemata – the Pascal way to get dynamic arrays without dirty tricks.
- Local variables may have dynamic size.
- Array Slice Access – access parts of an array as a smaller array, even on the left side of an assignment
- Compatible to Borland Pascal 7.0 with objects (BP):
- Supports units, objects, ..., and makes even things like absolute variables portable.
- Comes with portable versions of the BP standard units with full source.
- True network-transparent CRT unit: You can run your CRT applications locally or while being logged in remotely, without any need to worry about different terminal types. Compatible to BP's unit, but with many extensions, such as overlapping windows.
- Fully functional GUI (X11) version of CRT (also completely network transparent).
- The Random function can produce the same sequence of pseudo-random numbers as BP does – if you need that instead of the much more elaborate default algorithm.
- Supports BP style procedural variables as well as Standard Pascal's procedural parameters.
- A Ports unit lets you access CPU I/O ports on systems where this makes sense.
- Special compatibility features to help migrating from BP to GPC, like a GPC for BP unit which provides some of GPC's features for BP, and some routines to access sets of large memory blocks in a uniform way under GPC and BP (even in real mode).
- Comes with a BP compatible binobj utility.
- From Borland Delphi:
- abstract object types and methods
- is and as operators to test object type membership
- Comments with //
- Empty parameter lists with ()
- Assertions
- A SetLength procedure for strings makes it unnecessary to use dirty tricks like assignments to the “zeroth character”.
- Initialize and Finalize for low-level handling of variables.
- initialization and finalization for units.
- From Pascal-SC (PXSC):
- User-definable operators. Add your vectors with +.
- Carefully designed GNU extensions help you to make your real-world programs portable:
- 64-bit signed and unsigned integer types.
- Special types guarantee compatibility to other GNU languages such as GNU C. Directives like {$L foo.c} make it easy to maintain projects written in multiple languages, e.g., including code written in other languages into Pascal programs,
- or including Pascal code into programs written in other languages.
- Extensions like BitSizeOf and ConvertFromBigEndian help you to deal with different data sizes and endianesses.
- Little somethings like DirSeparator, PathSeparator, GetTempDirectory help you to write programs that look and feel “at home” on all operating systems.
- The PExecute routine lets you execute child processes in a portable way that takes full advantage of multitasking environments.
- The GNU GetOpt routines give you comfortable access to Unix-style short and long command-line options with and without arguments.
- Routines like FSplit or FSearch or FExpand know about the specifics of the various different operating systems.
- The FormatTime function lets you format date and time values, according to various formatting rules.
- Useful and portable GNU standard units:
- A Pipes unit gives you inter-process communication even under plain DOS.
- With the RegEx unit you can do searches with regular expressions.
- The GNU MultiPrecision (GMP) unit allows you to do arithmetics with integer, real, and rational numbers of arbitrary precision.
- Posix functions like ReadDir, StatFS or FileLock provide an efficient, easy-to-use and portable interface to the operating system.
- A DosUnix unit compensates for some of the incompatibilities between two families of operating systems.
- An MD5 unit to compute MD5 message digests, according to RFC 1321.
- A FileUtils unit which provides some higher-level file and directory handling routines.
- A StringUtils unit which provides some higher-level string handling routines.
- An Intl unit for internationalization.
- A Trap unit to trap runtime errors and handle them within your program.
- A TFDD unit that provides some tricks with text files, e.g. a “tee” file which causes everything written to it to be written to two other files.
- A HeapMon unit to help you find memory leaks in your programs.
The compiler supports the following language standards and quasi-standards:
Some highlights:
The demo programs mentioned above are available both on the WWW and in GPC source and binary distributions.
Disadvantages:
- The GNU debugger (GDB) still has some problems with Pascal debug info.
- Compilation with GPC takes quite long.