[M3devel] subranges 0..-1?
Jay K
jay.krell at cornell.edu
Mon Oct 4 19:16:05 CEST 2010
It worries me somewhat that we allow zero-sized types.
Including TYPE Foo = RECORD END;
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?
C requires a field. C++ adds a dummy one internally, 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, like:
TYPE T1 = RECORD END;
TYPE T2 = RECORD a,b:T1 END;
VAR a:T1;
ADR(a.b) # ADR(a.a.);
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?
As well this kind of thing worries me because Modula-3 truly is
mostly trivially isomorphic with C, which means it is easy to imagine
the gcc backend can handle it. This is an exception.
Sure, there probably is a transform to C, it just isn't obvious to me.
(Granted as well, the gcc backend handles Ada, and Pascal,
so it isn't so limited. Ada at least superficially looks like
Modula-3, I was surprised to see.)
- Jay
________________________________
> Subject: Re: [M3devel] subranges 0..-1?
> From: hosking at cs.purdue.edu
> Date: Mon, 4 Oct 2010 00:08:50 -0400
> CC: jay.krell at cornell.edu; m3devel at elegosoft.com
> To: ttmrichter at gmail.com
>
> It's an array with no elements, since the subrange [0..-1] is empty.
>
> On 3 Oct 2010, at 22:23, Michael Richter wrote:
>
> What does an ARRAY [0..-1] OF actually look like?
>
> On 3 October 2010 20:51, Jay K
> > wrote:
>
> ../src/Common/X.i3: In function 'X_I3':
> ../src/Common/X.i3:4845:0: internal compiler error: in
> m3cg_declare_subrange, at m3cg/parse.c:3567
>
>
> gcc_assert (min <= max);
>
> XClientMessageEvent = RECORD
> type: int;
> serial: unsigned_long; (* # of last request processed by server *)
> send_event: Bool; (* true if this came from a SendEvent
> request *)
> display: DisplayStar; (* Display the event was read from *)
> window: Window;
> message_type: Atom;
> format: int;
> alignment: ARRAY [0..-1] OF long;
> data: ARRAY [0..MAX (20 * BYTESIZE (char),
> MAX (10 * BYTESIZE (short),
> 5 * BYTESIZE (long))) - 1] OF char; END;
>
>
> alignment: ARRAY [0..-1] OF long;
>
>
> typedef struct {
> int type;
> unsigned long serial; /* # of last request processed by server */
> Bool send_event; /* true if this came from a SendEvent request */
> Display *display; /* Display the event was read from */
> Window window;
> Atom message_type;
> int format;
> union {
> char b[20];
> short s[10];
> long l[5];
> } data;
> } XClientMessageEvent;
>
>
>
> eh?
>
>
> I'll remove the assert.
> "Clearly"? the Modula-3 should just use an array of long though for the
> union?
>
>
> - Jay
>
>
>
>
>
> --
> "Perhaps people don't believe this, but throughout all of the
> discussions of entering China our focus has really been what's best for
> the Chinese people. It's not been about our revenue or profit or
> whatnot."
> --Sergey Brin, demonstrating the emptiness of the "don't be evil" mantra.
>
More information about the M3devel
mailing list