[M3devel] constants/offsetof?

Jay K jay.krell at cornell.edu
Mon Dec 27 08:15:26 CET 2010


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/bcf4f5ec/attachment-0001.html>


More information about the M3devel mailing list