[M3devel] constants/offsetof?
Tony Hosking
hosking at cs.purdue.edu
Mon Dec 27 18:20:25 CET 2010
I really don't understand yet what you are trying to achieve.
Do you have a distilled example?
Antony Hosking | Associate Professor | Computer Science | Purdue University
305 N. University Street | West Lafayette | IN 47907 | USA
Office +1 765 494 6001 | Mobile +1 765 427 5484
On Dec 27, 2010, at 2:15 AM, Jay K wrote:
> Is it unreasonble to expect more/all of these to be constant?
>
>
> UNSAFE MODULE bug1;
>
>
> TYPE T1 = RECORD i,j:INTEGER END;
>
>
> <*NOWARN*>VAR a:T1;
> <*NOWARN*>CONST b: UNTRACED REF T1 = NIL;
> <*NOWARN*>CONST c: ADDRESS = ADR(a); (* line 7 *)
> <*NOWARN*>CONST d: ADDRESS = ADR(a.i);
> <*NOWARN*>CONST e: ADDRESS = ADR(a.j);
> <*NOWARN*>CONST f: INTEGER = ADR(a.j) - NIL;
> <*NOWARN*>CONST g: ADDRESS = ADR(b.i);
> <*NOWARN*>CONST h: ADDRESS = ADR(b.j);
> <*NOWARN*>CONST i: INTEGER = ADR(b.j) - NIL;
>
> <*NOWARN*>VAR vc: ADDRESS := ADR(a);
> <*NOWARN*>VAR vd: ADDRESS := ADR(a.i);
> <*NOWARN*>VAR ve: ADDRESS := ADR(a.j);
> <*NOWARN*>VAR vf: INTEGER := ADR(a.j) - NIL; (* oops, didn't mean this one *)
> <*NOWARN*>VAR vg: ADDRESS := ADR(b.i);
> <*NOWARN*>VAR vh: ADDRESS := ADR(b.j);
> <*NOWARN*>VAR vi: INTEGER := ADR(b.j) - NIL;
>
> BEGIN
> END bug1.
>
>
> "../src/bug1.m3", line 7: value is not constant
> "../src/bug1.m3", line 8: value is not constant
> "../src/bug1.m3", line 9: value is not constant
> "../src/bug1.m3", line 10: value is not constant
> "../src/bug1.m3", line 11: value is not constant
> "../src/bug1.m3", line 12: value is not constant
> "../src/bug1.m3", line 13: value is not constant
>
> It works in C...
>
> #include <stddef.h>
>
> typedef struct { ptrdiff_t i, j;}T1;
>
> T1 a;
> #define b ((T1*)0)
> T1* const c = &a;
> ptrdiff_t* const d = &a.i;
> ptrdiff_t* const e = &a.j;
> ptrdiff_t const f = offsetof(T1,j);
> ptrdiff_t* const g = &b->i;
> ptrdiff_t* const h = &b->j;
> ptrdiff_t const i = &b->j - (ptrdiff_t*)0;
>
>
> Thanks,
> - Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20101227/5bbb9116/attachment-0002.html>
More information about the M3devel
mailing list