[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
NEW & extending redefinition
Hi.
Let's see if we can bring back a little bit of life to this mailing
list.
I recently noticed that NEW(v,n) doesn't check that `n' is a valid
length, or that it was actually able to allocate the required amount
of heap space. This raises two questions:
a) What is a valid length? A negative number is illegal and should
abort the program like any other failed run-time check. But is a
length of zero allowed?
Example:
VAR v: POINTER TO ARRAY OF CHAR;
...
NEW (v, 0)
Should this trigger a run-time check? Without pathological 0-length
arrays all iterations over open arrays are known to be executed at
least once (i.e., are REPEAT UNTIL loops), saving an extra test for
loops like "FOR i := 0 TO LEN(a)-1 DO".
b) Should a failed NEW() return NIL or trigger a run-time check? Most
code simply assumes that NEW will always bring back a new pointer, so
implementing the second alternative might be better.
Does anybody know how other compilers (preferably ETH ones) handle the
above situations?
Another topic is the adoption of the Oberon/F rule for the
redefinition of a type-bound procedure as suggested by A. Sheverdyaev.
Oberon/F relaxes the report to something like this: "If P' is a
redefinition of the type-bound procedure P, the formal parameters of P
and P' must match with the exception of the function result of P',
__which might be an extension of the one of P__."
The question is how this should be incorporated into OOC. I suggest
to implement two modes of operation for the compiler, "standard" (or
"conformant") and "extended". The mode is selected by a command line
option or by a pragma directive before a module's header. The former
mode would reject any modules that do not comply to the official
language specification. The latter would (for the moment) be less
restrictive about redefintions of type-bound procedures, and have a
WITH statement that won't rewrite a procedure's formal parameter list.
Any comments?
-- mva