Post by Arne Vajhøjhttps://www.vajhoej.dk/arne/articles/vmspascal.html
It is a "pre-release" - I am not sure I got it right.
So I would love some feedback.
You should get a native English speaker to edit for grammar.
C supports 'long double' which _may_ be the same as
`quadruple`, depending on the implementation, though
that's usually 80-bit floats. There is also _Float128,
_Quad, and __float128.
You mention `packed array` for dealing with character data,
but mention the usual, non-packed variant only in passing
later. It may be useful to explain the difference and why
it matters: `packed` originated on the CDC6500, where Wirth
wanted to fit multiple values into a machine word (that
was a word-oriented machine). You curiously don't mention
the String type at all. From
https://docs.vmssoftware.com/vsi-pascal-for-openvms-reference-manual/#STRING_TYPES_SEC:
|The STRING types provide a standard way for you to specify
|storage for varying-length character strings with a maximum
|length that can be specified at run time.
When discussing comparisons to other languages, you seem to
lump C, Java, and C# all in the same general bucket, which is
odd. Java and C# are closer to one another, but compared to
C they support rather different programming paradigms (OO and
some functional versus strictly procedural, or pseudo-OO
implemented by the programmer). It would be useful to state
clearly that VSI Pascal is a procedural language.
You write this:
|Pascal has pointers, but Pascal pointers are more like
|Java/C# references than C pointers.
|
|Pascal pointers can be used to allocate, to reference the
|allocated and to free the allocated. No fancy pointer arithmetic.
Don't bury the lede: if you're going to say that Pascal pointers
are "more like Java/C# references than C pointers" then say why
immediately, don't wait until the second sentence of the next
paragraph.
Also, "Pascal pointers can be used to allocate" doesn't make
much sense. Pointers can be used to point to allocated storage,
sure, but they are not themselves a memory allocator.
Here's a potential rewrite:
|Pascal has pointers: they can be null, and can point to
|allocated storage. But unlike C, they do not support pointer
|arithmetic. In this sense, they are closer to references in
|Java and C#.
I would not say that 'chr' and 'ord' are like casts in C.
Pascal is strongly, statically typed; C is weakly typed with
implicit conversions. Conversion between characters and integer
types in Pascal is an explicit operation, but `int c = 'a' + 1;`
is perfectly legal in C.
You give two C equivalents of, `round`: `lround` and
`ceil(v + 0.5)`. Surely the latter should be `trunc(v + 0.5)`:
term% cat d.c
#include <stdio.h>
#include <math.h>
int
main()
{
printf("ceil(0.2 + 0.5) = %g\n", ceil(0.2 + 0.5));
printf("ceil(0.6 + 0.5) = %g\n", ceil(0.6 + 0.5));
printf("trunc(0.6 + 0.5) = %g\n", trunc(0.6 + 0.5));
return 0;
}
term% make d
cc d.c -o d
: chandra; ./d
ceil(0.2 + 0.5) = 1
ceil(0.6 + 0.5) = 2
trunc(0.6 + 0.5) = 1
term%
But, consider negative numbers, and note that one would still
have to do a conversion to an integer type.
Similarly, Java's `Math.ceil` is not the same as Pascal's
`trunc`, unless the number is negative, and again there's the
integer conversion to consider.
Your C equivalent of `substr` is not correct; exercise left to
the reader (consider what happens when `ix` is beyond the end of
the string). For that matter, this is true of the VSI Pascal
example as well: you should specify the preconditions that must
be true.
You may want to mention that strings are origin 1, not origin 0,
as in most syntactically C-like languages. Also, array bounds
are inclusive in Pascal, unlike in C et al where the upper bound
is exclusive: `array [0..10] of integer` has 11 elements in
Pascal, while `array [1..10] of integer` has 10.
`readln` and `fgets` are not similar in that `readln` strips the
line ending sequence, and `fgets` does not.
`f = fopen,fnm "r");` is an obvious typo.
`while not eof(f)) do` is an obvious typo.
You might want to mention what `reset` and `rewrite` do. You
might want to mention `extend` and compare to `fopen(..., "a")`
or whatever.
You may want to mention that Pascal, the semicolon is a
statement separator, not a terminator, and hence why the last
"END" in the protocol is followed by "." and not ";".
The structure you present at the end as "equivalent" of a
varying character array is not correct. `integer16` is a signed
type, with a maximum value of 32,767. The length field for a
`varying [n] of char` is an integer subrange type with word
representation. That is, `length` is unsigned 0..max, where max
is <= 65,535.
- Dan C.