C++ doesn't have:
=
– assignment operation symbol (to avoid confusion with equal sign),ALGOL 68 doesn't have:
Intent | ALGOL 68 | C++ | ||
---|---|---|---|---|
Define a constant | '''int''' x=888; | |||
Initialise a variable | '''int''' x:=888; | |||
Assign a value 888 to a variable x | x:=888; | |||
Compare two values | '''if''' x = 888 '''then''' ... '''fi''' | |||
Allocate a variable from the heap | '''ref''' '''int''' x = '''heap''' '''int'''; or simply: '''heap''' '''int''' x; | |||
Compare address of two pointers | '''ref''' '''int''' x, y; '''if''' x :=: y '''then''' ... '''fi''' | |||
Compare value referenced by two pointers | '''ref''' '''int''' x, y; '''if''' x = y '''then''' ... '''fi''' | |||
Name a new type | '''mode''' '''longreal''' = '''long''' '''real'''; | or (as of C++11): | ||
Name a new record type | '''mode''' '''cust''' = '''struct'''('''string''' name, address); | |||
Name a new union type | '''mode''' '''taggedu''' = '''union'''('''string''' s, '''real''' r); | |||
Name a procedure or function | '''proc''' f = ('''real''' x) '''real''': (code; result); | |||
Procedure default parameters | '''proc''' p = ('''union''' ('''real''', '''void''') in x)'''void''': ('''real''' x = (in x | (real x):x | 888); code); | |
Name a new operator | '''op''' ↑ = ('''real''' x,y) '''real''': x**y; | |||
Set priority on a new operator | '''prio''' ↑ = 9; | |||
Chain variables assignment | a:=b:=c:=d; | |||
Displacement operator - ALGOL 68C only | a:=:=b:=:=c:=:=d; | |||
Append "substr" to a variable str | str +:= "substr"; | |||
Prefix "substr" to a variable str | "substr" +=: str; | |||
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'''
.
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: