community.borland.com

Article #15317: Turbo Pascal vs ANSI Pascal

 Technical Information Database

TI317D.txt - Turbo Pascal vs ANSI Pascal

Category   :Turbo Pascal
Platform   :All
Product    :

Description:

=================================================================
           Comparing Turbo Pascal 6.0 with ANSI Pascal
=================================================================


-----------------------------------------------------------------
                          Table of Contents
-----------------------------------------------------------------

 1. Exceptions to ANSI Pascal requirements
 2. Extensions to ANSI Pascal
 3. Implementation-dependent features
 4. Treatment of errors
-----------------------------------------------------------------

     This appendix compares Turbo Pascal to ANSI Pascal as
     defined by ANSI/IEEE770X3.97-1983 in the book American
     National Standard Pascal Computer Programming Language (ISBN
     0-471-88944-X, published by The Institute of Electrical and
     Electronics Engineers in New York).


===========================================
 1. Exceptions to ANSI Pascal requirements
===========================================

     Turbo Pascal is unable to detect whether a program violates
     any of the exceptions listed here.

     Turbo Pascal complies with the requirements of
     ANSI/IEEE770X3.97-1983 with the following exceptions:

     o In ANSI Pascal, an identifier can be of any length and all
     characters are significant. In Turbo Pascal, an identifier
     can be of any length, but only the first 63 characters are
     significant.

     o In ANSI Pascal, the 
 symbol is an alternative for the ^
     symbol.  In Turbo Pascal, the 
 symbol is an operator,
     which is never treated identically with the ^ symbol.

     o In ANSI Pascal, a comment can begin with { and end with
     *), or begin with (* and end with }. In Turbo Pascal,
     comments must begin and end with the same set of symbols.

     o In ANSI Pascal, each possible value of the tag type in a
     variant part must appear once. In Turbo Pascal, this
     requirement is not enforced.

     o In ANSI Pascal, the component type of a file type cannot
     be a structured type having a component of a file type. In
     Turbo Pascal, this requirement is not enforced.

     o In ANSI Pascal, a file variable has an associated buffer
     variable, which is referenced by writing the ^ symbol after
     the file variable. In Turbo Pascal, a file variable does not
     have an associated buffer variable, and writing the ^ symbol
     after a file variable is an error.

     o In ANSI Pascal, the statement part of a function must
     contain at least one assignment to the function identifier.
     In Turbo Pascal, this requirement is not enforced.

     o In ANSI Pascal, a field that is the selector of a variant
     part cannot be an actual variable parameter. In Turbo
     Pascal, this requirement is not enforced.

     o In ANSI Pascal, a component of a variable of a packed type
     cannot be an actual variable parameter. In Turbo Pascal,
     this requirement is not enforced.

     o In ANSI Pascal, a procedural or functional parameter is
     declared by writing a procedure or function heading in the
     formal parameter list. In Turbo Pascal, the declaration of a
     procedural or functional parameter is achieved through a
     procedural or functional type, and uses the same syntax as
     the declaration of other types of parameters.

     o In ANSI Pascal, the standard procedures Reset and Rewrite
     do not require pre-initialization of file variables. In
     Turbo Pascal, file variables must be assigned the name of an
     external file using the Assign procedure before they are
     passed to Reset or Rewrite.

     o ANSI Pascal defines the standard procedures Get and Put,
     which are used to read from and write to files. These
     procedures are not defined in Turbo Pascal.

     o In ANSI Pascal, the syntax New(p,c1,...,cn) creates a
     dynamic variable with a specific active variant. In Turbo
     Pascal, this syntax is not allowed.

     o In ANSI Pascal, the syntax Dispose(q,k1,...,km) removes a
     dynamic variable with a specific active variant. In Turbo
     Pascal, this syntax is not allowed.

     o ANSI Pascal defines the standard procedures Pack and
     Unpack, which are used to "pack" and "unpack" packed
     variables. These procedures are not defined in Turbo Pascal.

     o In ANSI Pascal, the term i mod j always computes a
     positive value, and it is an error if j is zero or negative.
     In Turbo Pascal, i mod j is computed as i - (i div j) * j,
     and it is not an error if j is negative.

     o In ANSI Pascal, a goto statement within a block can refer
     to a label in an enclosing block. In Turbo Pascal, this is
     an error.

     o In ANSI Pascal, it is an error if the value of the
     selector in a case statement is not equal to any of the case
     constants. In Turbo Pascal, this is not an error; instead,
     the case statement is ignored unless it contains an else
     clause.

     o In ANSI Pascal, statements that threaten the control
     variable of a for statement are not allowed. In Turbo
     Pascal, this requirement is not enforced.

     o In ANSI Pascal, a Read from a text file with a Char-type
     variable assigns a blank to the variable if Eoln was True
     before the Read. In Turbo Pascal, a carriage return
     character (ASCII 13) is assigned to the variable in this
     situation.

     o In ANSI Pascal, a Read from a text file with an integer-
     type or real-type variable ceases as soon as the next
     character in the file is not part of a signed integer or a
     signed number. In Turbo Pascal, reading ceases when the next
     character in the file is a blank or a control character
     (including the end-of-line marker).

     o In ANSI Pascal, a Write to a text file with a packed
     string-type value causes the string to be truncated if the
     specified field width is less than the length of the string.
     In Turbo Pascal, the string is always written in full, even
     if it is longer than the specified field width.

     o ANSI Pascal defines the standard procedure Page, which
     causes all subsequent output to a specific text file to be
     written on a new page. This procedure is not defined in
     Turbo Pascal. However, the typical equivalent of Page(F) is
     Write(F,Chr(12)).

==============================
 2. Extensions to ANSI Pascal
==============================

     Turbo Pascal is unable to detect whether a program uses any
     of the extensions listed here.

     The following Turbo Pascal features are extensions to Pascal
     as specified by ANSI/IEEE770X3.97-1983.

     o The following are reserved words in Turbo Pascal:

       absolute              inline                 shr
       assembler             interface              string
       constructor           interrupt              unit
       destructor            object                 virtual
       external              private                uses
       far                   near                   xor
       implementation        shl

     o An identifier can contain underscore characters (_).

     o Integer constants can be written in hexadecimal notation;
     such constants are prefixed by a $.

     o Identifiers can serve as labels.

     o String constants are compatible with the Turbo Pascal
     string types, and can contain control characters and other
     nonprintable characters.

     o Label, constant, type, variable, procedure, and function
     declarations can occur any number of times in any order in a
     block.

     o Wherever the syntax of ANSI Pascal requires a simple
     constant, Turbo Pascal allows the use of a constant
     expression (also known as a computed constant).

     o Turbo Pascal implements the additional integer types
     Shortint, Longint, Byte, and Word, and the additional real
     types Single, Double, Extended, and Comp.

     o Turbo Pascal implements string types, which differ from
     the packed string types defined by ANSI Pascal in that they
     include a dynamic-length attribute that can vary during
     execution.

     o Turbo Pascal implements procedural and functional types.
     In addition to procedural and functional parameters, these
     types make possible the declaration and use of procedural
     and functional variables.

     o The type compatibility rules are extended to make Char
     types and packed string types compatible with string types.

     o Variables can be declared at absolute memory addresses
     using an absolute clause.

     o A variable reference can contain a call to a pointer-type
     function, the result of which is then dereferenced to denote
     a dynamic variable.

     o String-type variables can be indexed as arrays to access
     individual characters in a string.

     o The type of a variable reference can be changed to another
     type through a variable typecast.

     o Turbo Pascal implements typed constants, which can be used
     to declare initialized variables of all types except file
     types.

     o Turbo Pascal implements three new logical operators: xor,
     shl, and shr.

     o The not, and, or, and xor operators can be used with
     integer-type operands to perform bitwise logical operations.

     o The + operator can be used to concatenate strings.

     o The relational operators can be used to compare strings.

     o Turbo Pascal implements the 
 operator, which is used to
     obtain the address of a variable or a procedure or function.

     o The type of an expression can be changed to another type
     through a value typecast.

     o The case statement allows constant ranges in case label
     lists, and provides an optional else part.

     o Procedures and functions can be declared with external,
     inline, and interrupt directives to support assembly
     language subroutines, inline machine code, and interrupt
     procedures.

     o A variable parameter can be untyped (typeless), in which
     case any variable reference can serve as the actual
     parameter.

     o Turbo Pascal implements units to facilitate modular
     programming and separate compilation.

     o Turbo Pascal implements the following file-handling
     procedures and functions, which are not available in ANSI
     Pascal:

       Append               FilePos                 Rename
       BlockRead            FileSize                RmDir
       BlockWrite           Flush                   Seek
       ChDir                GetDir                  SeekEof
       Close                MkDir                   SeekEoln
       Erase

     o String-type values can be input and output with the Read,
     Readln, Write, and Writeln standard procedures.

     o Turbo Pascal implements the following standard procedures
     and functions, which are not found in ANSI Pascal:

       Addr                 Inc                    Ptr
       Concat               Insert                 Random
       Copy                 Int                    Randomize
       CSeg                 Length                 Release
       DSeg                 Lo                     RunError
       Dec                  Mark                   SPtr
       Delete               MaxAvail               Seg
       Exit                 MemAvail               SizeOf
       FillChar             Move                   SSeg
       Frac                 Ofs                    Str
       FreeMem              ParamCount             Swap
       GetMem               ParamStr               TypeOf
       Halt                 Pi                     UpCase
       Hi                   Pos                    Val

     o Turbo Pascal implements further standard constants, types,
     variables, procedures, and functions through standard units.


======================================
 3. Implementation-dependent features
======================================

     The effect of using an implementation-dependent feature of
     Pascal, as defined by ANSI/IEEE770X3.97-1983, is
     unspecified.  Programs should not depend on any specific
     path being taken in cases where an implementation-dependent
     feature is being used.  Implementation-dependent features
     include:

     o the order of evaluation of index expressions in a variable
     reference

     o the order of evaluation of expressions in a set
     constructor

     o the order of evaluation of operands of a binary operator

     o the order of evaluation of actual parameters in a function
     call

     o the order of evaluation of the left and right sides of an
     assignment

     o the order of evaluation of actual parameters in a
     procedure statement

     o the effect of reading a text file to which the procedure
     Page was applied during its creation

     o the binding of variables denoted by the program parameters
     to entities external to the program


========================
 4. Treatment of errors
========================

     This section lists those errors from Appendix D of the ANSI
     Pascal Standard that are not automatically detected by Turbo
     Pascal. The numbers referred to here are the numbers used in
     the ANSI Pascal Standard. Errors 6, 19-22, and 25-31 are not
     detected because they are not applicable to Turbo Pascal.

     2. If t is a tag field in a variant part and f is a field
     within the active variant of that variant part, it is an
     error to alter the value of t while a reference to f exists.
     This error is not detected.

     3. If p is a pointer variable, it is an error to reference
     p^ if p is nil. This error is not detected.

     4. If p is a pointer variable, it is an error to reference
     p^ if p is undefined. This error is not detected.

     5. If p is a pointer variable, it is an error to alter the
     value of p while a reference to p^ exists. This error is not
     detected.

     42. The function call Eoln(f) is an error if Eof(f) is True.
     In Turbo Pascal this is not an error, and Eoln(f) is True
     when Eof(f) is True.

     43. It is an error to reference a variable in an expression
     if the value of that variable is undefined. This error is
     not detected.

     46. A term of the form i mod j is an error if j is zero or
     negative. In Turbo Pascal, it is not an error if j is
     negative.

     48. It is an error if a function does not assign a result
     value to the function identifier. This error is not
     detected.

     51. It is an error if the value of the selector in a case
     statement is not equal to any of the case constants. In
     Turbo Pascal, this is not an error; instead, the case
     statement is ignored unless it contains an else clause.


Reference:
 

3/30/99 1:04:56 PM
 

Last Modified: 01-SEP-99