This article will explain Modula-2 for Pascal programmers.
C/C++/Java/C# programmers should go here.
Getting started with Modula-2 is really easy for Pascal programmers.
You just write Pascal code with the following changes:
Let us see a few examples.
Array:
Record:
Procedure:
Pointer and dynamic allocation:
Set:
All very similar to Pascal.
Modula-2 string procedures are similar to Delphi string procedures (standard Pascal does not have such and VMS Pascal string procedures are different).
Example:
A few areas are very different from Pascal:
Let us take a simple Delphi/FPC example.
program Test(input,output);
{$MODE OBJFPC}
uses
Classes, SysUtils;
type
Acc = class(TObject)
private
v : integer;
public
constructor Create;
procedure Inc;
function Get : integer;
procedure Free;
end;
constructor Acc.Create;
begin
v := 0;
end;
procedure Acc.Inc;
begin
v := v + 1;
end;
function Acc.Get : integer;
begin
Get := v;
end;
procedure Acc.Free;
begin
end;
var
a : Acc;
i : integer;
begin
a := Acc.Create;
for i := 1 to 3 do begin
a.Inc;
end;
writeln(a.Get():1);
a.Free;
end.
Version | Date | Description |
---|---|---|
1.0 | August 27th 2021 | Initial version |
1.1 | August 28th 2021 | Add system/coroutines/c interface section |
1.2 | September 2nd 2021 | Update C interface section and add assembler example |
See list of all articles here
Please send comments to Arne Vajhøj