Английская Википедия:Comparison of ALGOL 68 and C++

Материал из Онлайн справочника
Перейти к навигацииПерейти к поиску

Шаблон:No footnotes Шаблон:ProgLangCompare

C++ doesn't have:

ALGOL 68 doesn't have:

Comparison of the assignment and equality operators

Intent ALGOL 68 C++
Define a constant int x=888; Шаблон:Cpp
Initialise a variable int x:=888; Шаблон:Cpp
Assign a value 888 to a variable x x:=888; Шаблон:Cpp
Compare two values if x = 888 then ... fi Шаблон:Cpp
Allocate a variable from the heap ref int x = heap int;
or simply:
heap int x;
Шаблон:Cpp
Compare address of two pointers ref int x, y;
if x :=: y then ... fi
Шаблон:Cpp

Шаблон:Cpp

Compare value referenced by two pointers ref int x, y;
if x = y then ... fi
Шаблон:Cpp

Шаблон:Cpp

Name a new type mode longreal = long real; Шаблон:Cpp
or (as of C++11):
Шаблон:Cpp
Name a new record type mode cust = struct(string name, address); Шаблон:Cpp
Name a new union type mode taggedu = union(string s, real r); Шаблон:Cpp
Name a procedure or function proc f = (real x) real: ( code; result ); Шаблон:Cpp
Procedure default parameters proc p = (union (real, void) in x)void:

    ( real x = (in x|(real x):x|888); code );

Шаблон:Cpp
Name a new operator op ↑ = (real x,y) real: x**y; Шаблон:N/a
Set priority on a new operator prio ↑ = 9; Шаблон:N/a
Chain variables assignment a:=b:=c:=d; Шаблон:Cpp
Displacement operator - ALGOL 68C only a:=:=b:=:=c:=:=d; Шаблон:Cpp
Append "substr" to a variable str str +:= "substr"; Шаблон:Cpp
Prefix "substr" to a variable str "substr" +=: str; Шаблон:Cpp

Code Examples

Union declaration and use

Assigning values into an A68 union variable is automatic, the type is "tagged" to the variable, but pulling the value back out is syntactically awkward as a conformity-clause is required.

ALGOL 68 example:

 union(int, char) x:=666;
 printf(($3d l$, (x|(int i):i) ))

C++ example:

  union { int i; char c; } x = { 666 };
  std::cout << x.i << std::endl;

The net effect of "type-tagging" is that Algol68's strong typing "half" encroaches into the union.

Mode declaration

A new mode (type) may be declared using a mode declaration:

int max=99;
mode newtype = [0:9][0:max]struct (
   long real a, b, c, short int i, j, k, ref real r
);

This has the similar effect as the following C++ code:

const int max=99;
typedef struct { 
    double a, b, c; short i, j, k; float& r;
} newtype[9+1][max+1];

Note that for ALGOL 68 only the newtype name appears to the left of the equality, and most notably the construction is made - and can be read - from left to right without regard to priorities.

External links

Шаблон:C++ programming language