Comparison of Pascal and Delphi
{{Short description|Programming language}}
{{ProgLangCompare}}
{{use mdy dates|date=April 2023}}
Devised by Niklaus Wirth in the late 1960s and early 1970s, Pascal is a programming language. Originally produced by Borland Software Corporation, Embarcadero Delphi is composed of an IDE, set of standard libraries, and a Pascal-based language commonly called either Object Pascal, Delphi Pascal, or simply 'Delphi' (Embarcadero's current documentation refers to it as 'the Delphi language (Object Pascal)'{{Cite web|url=http://docwiki.embarcadero.com/RADStudio/XE2/en/Delphi_Reference|title = Delphi Reference - RAD Studio XE2}}). Since first released, it has become the most popular commercial Pascal implementation.
While developing Pascal, Wirth employed a bootstrapping procedure in which each newer version of the Pascal compiler was written and compiled with its predecessor. Thus, the 'P2' compiler was written in the dialect compilable by 'P1', 'P3' in turn was written in 'P2' and so on, all the way till 'P5'. The 'P5' compiler implemented Pascal in its final state as defined by Wirth, and subsequently became standardised as 'ISO 7185 Pascal'.
The Borland dialect, like the popular UCSD Pascal before it, took the 'P4' version of the language as its basis, rather than Wirth's final revision. After much evolution independent of Standard Pascal, the Borland variant became the basis for Delphi. This page goes over the differences between Delphi and Standard Pascal. It does not go into Delphi-specific extensions to the language, which are numerous and still increasing.
Exclusive features
Following features are mutually exclusive.
The Standard Pascal implementation is not accepted by Delphi and vice versa, the Delphi code is not acceptable in Standard Pascal.
= Modulo with negative dividend =
Standard Pascal has a Euclidean-like definition of the
= Nested comments =
Standard Pascal requires that the comment delimiters
In Delphi, however, a block comment started by
The bigramm
This scheme allows for nested comments at the expense of compiler complexity.
= Procedural data types =
The way procedures and functions can be passed as parameters differs:
Delphi requires explicit procedural types to be declared where Standard Pascal does not.
class="wikitable" style="margin: auto;"
|+ comparison procedural data types | |
Standard Pascal | Delphi |
---|---|
style="vertical-align:bottom"
| program proceduralDataType(output); { `printYIntersect` has one procedural parameter: } procedure printYIntersect(function f(x: real): real); begin writeLn(f(0.0)); end; { Standard Pascal does not have procedural “pointers.” } function f(x: real): real; begin f := cos(x); end; { ─── MAIN ───────────────────────────────────────────── } begin printYIntersect(f); end. | type TFunc = function(x: real): real; procedure printYIntersect(f: TFunc); begin writeLn(f(0.0)); end; function f(x: real): real; begin f := cos(x); end; // ─── MAIN ───────────────────────────────────────────── begin printYIntersect(@f); end. |
= Conversion of newline characters =
Various computer systems show a wide variety how to indicate a newline.
This affects the internal representation of
In order to relieve the programmer from any associated headaches, Standard Pascal mandates that reading an “end-of-line character” returns a single space character.
To distinguish such an “end-of-line” space character from a space character that is actually genuine payload of the line,
Delphi does not show this behavior.
Reading a newline will return whatever character sequence represents a newline on the current host system, for example two
Additional or missing features
Following features are present or missing in either language.
= Global <syntaxhighlight lang="pascal" inline>goto</syntaxhighlight> =
= Buffer variables =
Delphi does not support buffer variables and associated standard routines
begin
while not EOF(input) do
begin
{ Copy file buffers. Not supported by Delphi }
output↑ := input↑;
{ Input↑ contains a space if a new-line occurred. }
if EOLn(input) then
begin
writeLn(output);
end
else
begin
put(output);
end;
{ Advance reading cursor. }
get(input);
end;
end.
= Discriminated variant record allocation =
In Standard Pascal allocating memory for a variant
This allows implementations to allocate the least amount of really necessary memory.
type
sex = (female, male);
clothingMeasures = record
girth: real;
case gender: sex of
female: (underbust: real);
male: ( );
end;
var
size: clothingMeasures;
begin
{ NB: No space allocated for `underbust`. }
new(size, male);
end.
= Temporary files =
In Delphi any file must be backed by a file in the file system.
That means any
In contrast, Standard Pascal is usable without file names.
The following will produce a run-time error with Delphi.
var
FD: text;
begin
rewrite(FD);
writeLn(FD, 'Hello world!');
end.
= Packing =
= Missing default <syntaxhighlight lang="pascal" inline>write</syntaxhighlight> width =
= Overloading =
Delphi permits overloading routines.
In Standard Pascal identifiers must be unique in every block.
begin
result := sin(x);
end;
function f(x: real): real;
begin
result := cos(x);
end;
// ─── MAIN ─────────────────────────────────────────────
begin
// Note the different data types.
writeLn(f(3));
writeLn(f(3.0));
end.
= Default parameter values =
Delphi permits default parameters.
Peculiar implementation characteristics
= Standard <syntaxhighlight lang="pascal" inline>write</syntaxhighlight> width =
In Pascal, if the destination file is a
In Delphi, for
That means always the least amount of space is occupied.
Other compilers have shown default widths of, for example,
class="wikitable" style="margin: auto;"
|+ comparison default | |
colspan="2" | source code fragment | |
---|---|
colspan="2" | writeLn(23456789); | |
colspan="2" | produces in | |
Standard Pascal (GPC) | Delphi |
23456789 | 23456789 |
References
| title = The GNU Pascal Manual
| first1 = Jan-Jaap
| last1 = van der Heijden
| first2 = Peter
| last2 = Gerwinski
| first3 = Frank
| last3 = Heckenbach
| first4 = Berend
| last4 = deBoer
| first5 = Dominik
| last5 = Freche
| first6 = Eike
| last6 = Lange
| first7 = Peter
| last7 = Lewis
| display-authors = etal
| at = A QuickStart Guide from Borland Pascal to GNU Pascal
| url = https://www.GNU-Pascal.de/gpc/Comments.html#Comments
| access-date = 2023-04-24
}}
| title = Pascal Standards FAQ
| at = Comparison of Borland Pascal to the Pascal standards
| first = John
| last = Reagan
| date = 1995-04-03
| url = http://Pascal-Central.com/extpascal.html#anchor-6
| archive-url = https://web.archive.org/web/20210928162340/http://pascal-central.com/extpascal.html#anchor-6
| archive-date = 2021-09-28
}}
| title = Standard Pascal FAQ
| at = Q. What are the differences between Borland Delphi and the ISO 7185 standard?
| first = Scott
| last = Moore
| date = 2022-12-02
| url = https://www.MooreCAD.com/standardpascal/pascalfaq.html#Q.%20What%20are%20the%20differences%20between%20Borland%20Del
| access-date = 2023-04-24
}}
Further reading
- Kathleen Jansen and Niklaus Wirth: PASCAL - User Manual and Report. Springer-Verlag, 1974, 1985, 1991, {{ISBN|0-387-97649-3}}, {{ISBN|0-387-90144-2}}, and {{ISBN|3-540-90144-2}} [https://web.archive.org/web/20050314152247/http://www.cs.inf.ethz.ch/~wirth/books/Pascal/]
- Niklaus Wirth: The Programming Language Pascal. Acta Informatica, 1, (Jun 1971) 35–63
- ISO/IEC 7185: Programming Languages - PASCAL. [http://www.moorecad.com/standardpascal/]
- Doug Cooper: Standard Pascal: User Reference Manual. W. W. Norton & Company, 1983, {{ISBN|0-393-30121-4}}, {{ISBN|978-0-393-30121-2}}
External links
- [https://www.moorecad.com/standardpascal/ The ISO 7185 Pascal web site]
- [https://www.StandardPascal.org/standards.html Pascal standards documents]
{{Pascal programming language family}}
{{DEFAULTSORT:Pascal and Delphi comparison}}