[M3devel] zero sized structs?

mika at async.caltech.edu mika at async.caltech.edu
Thu Oct 4 23:51:02 CEST 2012


> > (of course the report also says that "The reference returned by NEW is d=
>istinct from all existing references") Aha. Good.And doesn't it seem kind o=
>f nice and correct if that same sort of thing applied to locals and globals=
>?More consistent that way? 

Well either way it's just not visible from the safe subset of the language...

>Really I wouldn't mind if ARRAY [0..0] or ARRAY =
>[0..-1] was just plain illegal.The following are not legal standard C/89/90=

Sure but C doesn't have a type [0..-1] either... and I don't think
you can get away without those sorts of types (called "empty types" in
the report).  HOWEVER, declaring a variable of an empty type or NEWing
an empty type is a static error...

There's a little section in the report about "making non-empty types out
of empty types".  The example is 

x : [0..-1]; (* illegal *)

y := NEW(REF [0..-1]); (* illegal *)

s : SET OF [0..-1]; (* legal *)

s is legal because the type isn't empty; it contains the empty set.
Likewise I suppose ARRAY OF [0..-1] also is legal because it contains
the empty array.  But sure there's a stronger argument for ruling the
latter illegal than the former.  The problem is, though, that that leaves
you no way of statically declaring an array of size zero, which is certainly
a useful concept.  E.g.,

x : REF ARRAY OF INTEGER := NEW(REF ARRAY OF INTEGER, 0);

...

WITH new = NEW(REF ARRAY OF INTEGER, NUMBER(x^) + 1) DO
  SUBARRAY(new^, 0, NUMBER(x^)) := x^;
  new[LAST(new^)] := newElement;
END
...

So I don't use [0..-1] here but you could certainly see xx : ARRAY [0..-1]
OF INTEGER as being compatible with the initial value of x. 

     Mika




More information about the M3devel mailing list