New as function
Frank Heckenbach
ih8mj at fjf.gnu.de
Sun Jul 24 18:40:16 CEST 2005
CBFalconer wrote:
> Peter N Lewis wrote:
> >
> ... snip ...
> >
> > New(s,57) gives a runtime error on failure, and so the compiler
> > knows that it need not bother checking.
> >
> > s := New(String,57) potentially returns nil, so the compiler checks.
> >
> > I'm not sure if that is reasonable. It makes a certain kind of
> > sense in some respects - New as a procedure has no return value and
> > thus nothing to report, New as a function returns a pointer (even
> > for reference objects anyway) and therefore can return a
> > success/failure result.
>
> To start with, new is a standard PROCEDURE, not a function. The
> constants following the argument specify variants and allow
> assignment of space for a particular variant of the actual type.
> You can only do the sort of thing you recommend if you override the
> level 0 predeclaration of new, which in turn makes memory
> allocation unavailable to the remainder of the program.
There are two issues here:
1. `New' applied to schemata, including `String', is an ISO 10206
standard feature. (It uses a similar syntax as `New' for variant
records, but there are no conflicts.) Of all the various
suggestions to allocate variables with dynamic size at runtime,
that's the cleanest one I know. Please note that ISO 7185 has no
way to do this at all. It has conformant array parameters (in
level 1), but in the (ultimate) caller, the arrays have to have a
compile-time known size. Do you suggest abandoning
dynamically-sized types completely?
2. `New' as a function is a GPC (and in other contexts, namely
objects, also a BP) extension. That's basically just syntactic
sugar that doesn't add a lot, but also doesn't hurt much ...
If you want to criticize nonstandard features (2.) so harshly, you
might want to attention not to attack standard features (1.) as well
...
Frank
--
Frank Heckenbach, frank at g-n-u.de, http://fjf.gnu.de/, 7977168E
GPC To-Do list, latest features, fixed bugs:
http://www.gnu-pascal.de/todo.html
GPC download signing key: ACB3 79B2 7EB2 B7A7 EFDE D101 CD02 4C9D 0FE0 E5E8
More information about the Gpc
mailing list