[M3devel] zero sized structs?
Jay
jay.krell at cornell.edu
Thu Oct 4 21:33:33 CEST 2012
Same address & same size implies same object & same type. But the types can vary. Please check also variables in sub-blocks. I think NT/x86 backend doesn't always put them at same place. Then again, that is probably ok too -- in general not all zero sized objects can be located -- they could be locals in different functions or globals in different modules.
You say use a different language, but 1) they are exceedingly rare so ok to waste space 2) as small & simple Modula-3 is, it is still really isn't small or simple, there are surprising number & level of detail to understand and deal with. Adding a notion of a zero sized thing isn't necessarily so obviously simple and free of complexity down the line.
- Jay (briefly/pocket-sized-computer-aka-phone)
On Oct 4, 2012, at 11:23 AM, <mika at async.caltech.edu> wrote:
> It seems that CM3 puts them at the "same address"....
>
> UNSAFE MODULE Main;
> IMPORT IO, Fmt;
>
> TYPE
> T = ARRAY [1..-1] OF INTEGER;
>
> VAR t := NEW(REF T); u := NEW(REF T);
> v : T;
> w : T;
> BEGIN
> IO.Put(Fmt.Int(LOOPHOLE(t,INTEGER), base := 16) & "\n");
> IO.Put(Fmt.Int(LOOPHOLE(u,INTEGER), base := 16) & "\n");
> IO.Put(Fmt.Int(LOOPHOLE(ADR(v),INTEGER), base := 16) & "\n");
> IO.Put(Fmt.Int(LOOPHOLE(ADR(w),INTEGER), base := 16) & "\n");
> END Main.
>
> (114)async:~/ttt/src>../AMD64_LINUX/prog
> 2269030
> 2269040
> 602218
> 602218
>
> I don't see a problem with it. Whoever thinks he needs to check whether
> ADR(v) equals ADR(w) should be using a different programming language...
>
> Mika
>
More information about the M3devel
mailing list