请输入您要查询的百科知识:

 

词条 Comparison of ALGOL 68 and C++
释义

  1. Comparison of the assignment and equality operators

  2. Code Examples

     Union declaration and use  Mode declaration 

  3. External links

{{no footnotes|date=June 2013}}{{ProgLangCompare}}

C++ doesn't have:

  • PROC - first class nested functions (emulation due to local definitions of class-types, which then could be functors, also new C++11 has lambda functions),
  • OP and PRIO - definable operator symbols and priorities,
  • garbage collection (could be emulated with help of smart pointers),
  • use before define,
  • formatted transput using complex formatting declarations,
  • := - assignment operation symbol (to avoid confusion with equal sign),
  • array (and slice operations on them, but in layered libraries),
  • automatic UNIONs,
  • CASE expressions,
  • nonlocal GOTO
  • intuitive declaration syntax due to its origin from C.

ALGOL 68 doesn't have:

  • public/private struct member access protection,
  • overloaded procedures (in contrast to operators),
  • explicit memory deallocation,
  • forward declarations (use before definition is allowed)
  • textual preprocessing (e.g. macros),
  • distinct reference and pointer types,
  • comment lines (only bracketed comments),
  • struct inheritance, struct member functions, virtual functions.
  • destructors, exceptions, templates, namespaces, structured loop exits

Comparison of the assignment and equality operators

Intent ALGOL 68 C++
Define a constant int x=888; 1=const int x = 888;}}
Initialise a variable int x:=888; 1=int x = 888;}}
Assign a value 888 to a variable x x:=888; 1=x = 888;}}
Compare two values if x = 888 then ... fi 1=if (x == 888) { ... } }}
Allocate a variable from the heap ref int x = heap int;
or simply:
heap int x;
1=int* x = new int;}}
Compare address of two pointers ref int x, y;
if x :=: y then ... fi
1=int* x; int* y;}}
{{cpp|1=if (x == y) { ... } }}
Compare value referenced by two pointers ref int x, y;
if x = y then ... fi
1=int* x; int* y;}}
{{cpp|1=if (*x == *y) { ... } }}
Name a new type mode longreal = long real; 1=typedef double longreal;}}
or (as of C++11):
{{cpp|1=using longreal = double;}}
Name a new record type mode cust = struct(string name, address); 1=struct cust { std::string name, address; }; }}
Name a new union type mode taggedu = union(string s, real r); 1=union u { std::string s; float f; }; }}
Name a procedure or function proc f = (real x) real: ( code; result ); 1=float f(float x) { code; return result; } }}
Procedure default parameters proc p = (union (real, void) in x)void:

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

1=void p(float x=888) { code; } }}
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; 1=a = b = c = d;}}
Displacement operator - ALGOL 68C only a:=:=b:=:=c:=:=d; 1=a = b; b = c; c = d;}}
Append "substr" to a variable str str +:= "substr"; 1=str += "substr";}}
Prefix "substr" to a variable str "substr" +=: str; 1=str = "substr" + str;}}

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/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 {

} 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

  • A comparison of PASCAL and ALGOL 68 - Andrew S. Tanenbaum - June 1977.
  • [https://web.archive.org/web/20110609175836/http://remus.rutgers.edu/cs314/s2004/ryder/lectures/intro-1-2upNew.pdf Orthogonal language design] - Apr 2004 - retrieved May 10, 2007
  • [https://web.archive.org/web/20060113120427/http://remus.rutgers.edu/cs314/s2004/ryder/lectures/formal-4-2upNew.pdf How Solve the Dangling Else?] - Apr 2004 - retrieved May 10, 2007
  • [https://web.archive.org/web/20060113120810/http://remus.rutgers.edu/cs314/s2004/ryder/lectures/Types2-23New-2up.pdf A comparison of Pascal, C, C++ and Algol68: Types, cont Type system, Type checking, Type safety, Type conversion, Primitive types, Aggregate types: arrays] - Apr 2004 - retrieved May 10, 2007
  • [https://web.archive.org/web/20110609180018/http://remus.rutgers.edu/cs314/s2004/ryder/lectures/Types-22-425-2up.pdf Arrays in Algol68] - Apr 2004 - retrieved May 10, 2007
  • A Comparison of Arrays in ALGOL 68 and BLISS - Michael Walker - February 21, 2000 - retrieved December 21 2015
{{DEFAULTSORT:ALGOL 68 and C comparison}}

5 : Comparison of individual programming languages|ALGOL 68|C++|Articles with example ALGOL 68 code|Articles with example C++ code

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/30 18:20:54