[M3devel] subranges 0..-1?

Mika Nystrom mika at async.async.caltech.edu
Mon Oct 4 20:12:08 CEST 2010


Jay K writes:
>
>It worries me somewhat that we allow zero-sized types.
>Including TYPE Foo =3D RECORD END=3B
>It is reassuring to me that C and C++ doesn't have these.
>I don't want to think about what they mean.
>Do they make sense to others?

Yes, they make a lot of sense.  Not having them means special-casing
any program that generates code.  Obviously a correct program that generates
code including a zero-sized array will never generate an expression
that indexes such an array...

>
>C requires a field. C++ adds a dummy one internally=2C that it can/must try
>to optimize away when inheritance is involved but still.
>
>
>C++ is interested in the property of pointers not being equal=2C like:
>
>TYPE T1 =3D RECORD END=3B
>TYPE T2 =3D RECORD a=2Cb:T1 END=3B
>
>VAR a:T1=3B
>ADR(a.b) # ADR(a.a.)=3B
>
>But in Modula-3 they would have the same address.
>What does it mean to take the address of something that doesn't exist?
>Perhaps it isn't allowed?

This is UNSAFE code, so it means whatever the implementation makes
it mean, including (as far as I'm concerned) a compiler crash, if
that is the easiest thing you can make it mean.  I really wouldn't
worry about the UNSAFE parts of Modula-3 that much...  expected to be
implementation-dependent.  Although I admit it would be better to have
it do something meaningless in this case.  Since T1 is an empty type
there's not much you can do with the address anyhow.

    Mika



More information about the M3devel mailing list