This is a very interesting discussion for me, as I am the current
maintainer of "New Stanford Pascal".
I am trying to extend the language to make it more usable, while not
violating the Pascal spirit.
Inspiration and motivation are the different versions of IBM's Pascal
(Pascal/VS and VS/Pascal),
available for MVS and VM/CMS starting from ca. 1980 on.
I recently added MEMCPY, MEMSET and MEMCMP; I allowed to take the ADDR
of every object
(that is, pointers do not only exist for dynamically created variables,
via NEW), and I added new functions
ALLOC and FREE, which do a better job in storage allocating than NEW and
DISPOSE (DISPOSE,
in fact, was never implemented in the "old" Stanford compiler; it only
had some global heap
freeing mechanism using MARK and RELEASE).
The NULL pointer (called NIL in Pascal) is implemented as 0xFFFFFFFF
(minus one), so that
MEMSETting a struct containing pointers indeed will not yield NIL
pointers; you have to
set the pointers explicitly to NIL after the MEMSET. Dereferencing a NIL
pointer will give
a 0C4 abend on the mainframe; if you want, you can create a DEBUG
version of the program
which checks for NIL before dereferencing and throws a Pascal runtime
error.
Regarding pointer arithmetic:
it is not allowed to add an integer value to a pointer directly, but
there is a function called PTRADD (p, i), which adds an integer value i
to a pointer p.
i may be positive or negative.
The pointer p is of type ANYPTR (or VOIDPTR), which is a ptr type
compatible to all
other pointer types. The result of PTRADD is of type ANYPTR, too.
In contrast to C, PTRADD adds byte addresses, not elements.
PTRADD (p, 0) is used to cast pointer types (pointers are typed pointers
in Pascal);
it can be coded as PTRCAST (p), too.
PTRDIFF (p1, p2) with integer result is the distance between two pointers.
There are functions like SIZEOF etc., which work much the same way as
their C counterparts.
All those functions have to be used with care, because the normal
runtime checks
(array index limits, subrange, scalar types) do not apply.
The compiler works the same on the mainframe and on Windows/Linux etc.
(since 2016, before 2016, it was mainframe-only)
More information and download:
https://github.com/StanfordPascal/Pascal
Kind regards
Bernd
Am 13.09.2020 um 13:47 schrieb Thomas David Rivers:
Charles Mills <[email protected]> wrote:`
I would think if you were going to design a rigorous language you would not
have a memset() as part of the language or its included library. Memset
implicitly treats its target as a union between whatever it actually is and
an array of chars. So using memset kind of violates the restriction I speak
of in the first paragraph.
Yes - that is a good point. I think such a rigorous language might
lead you down to something like PASCAL-0, which turned out to be wonderful
in a lot of ways, but not too practical.
Not to defend "C" - I don't really disagree with your point; but I
think a nod-toward-practicality is what lead to some of the
choices we now live with.
- Dave R. -