<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><div>For the record, I didn't do this, way back even in:</div><div><br></div><div><br></div><div>https://modula3.elegosoft.com/cgi-bin/cvsweb.cgi/cm3/m3-sys/m3middle/src/Target.m3?rev=1.1;content-type=text%2Fplain</div><div><br></div><div><br></div><div>we had:</div><div><br></div><div><br></div><div>    (* build a generic 32-bit/IEEE system description *)</div><div><br></div><div>    Int64.cg_type    := CGType.Int64;</div><div>    Int64.size       := 64;</div><div>    Int64.align      := 64;</div><div>    Int64.min.x      := IChunks { 00, 00, 00, 16_8000 };</div><div>    Int64.max.x      := IChunks { FF, FF, FF, 16_7fff };</div><div><br></div><div><br></div><div><br></div><div>This is likely wrong on many/most/all 32bit targets.</div><div><br></div><div><br></div><div><br></div><div>Int64 is likely to be loaded/stored with two 32bit operations, <span style="font-size: 12pt;">therefore align probably should be 32.</span></div><div><br></div><div><br></div><div>At the time, I don't think there was any way to use this type, i.e.</div><div>there was no LONGINT.</div><div><br></div><div><br></div><div>Once LONGINT came into being, if you wrote:</div><div><br></div><div><br></div><div>foo.m3</div><div>RECORD</div><div>  a: Ctypes.int;</div><div>  b: LONGINT</div><div>END;</div><div><br></div><div><br></div><div>and foo.c:</div><div>struct </div><div>{</div><div> int a;</div><div> long long b;</div><div>};</div><div><br></div><div><br></div><div>you would probably get different layout.</div><div><br></div><div><br></div><div>Let's see:</div><div><br></div><div><br></div><div>jair:src jay$ cat 1.c</div><div>int a = sizeof(struct </div><div>{</div><div> int a;</div><div> long long b;</div><div>});</div><div>jair:src jay$ cc -c -S -m32 1.c</div><div>jair:src jay$ cat 1.s</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>.section<span class="Apple-tab-span" style="white-space:pre">    </span>__TEXT,__text,regular,pure_instructions</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>.macosx_version_min 10, 10</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>.section<span class="Apple-tab-span" style="white-space:pre">    </span>__DATA,__data</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>.globl<span class="Apple-tab-span" style="white-space:pre">      </span>_a                      ## @a</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>.align<span class="Apple-tab-span" style="white-space:pre">      </span>2</div><div>_a:</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>.long<span class="Apple-tab-span" style="white-space:pre">       </span>12                      ## 0xc</div><div><br></div><div><br></div><div>jair:1 jay$ cat 1.c src/Main.m3 src/m3makefile </div><div>#include <stdio.h></div><div><br></div><div>int main()</div><div>{</div><div>printf("%d\n", (int)sizeof(struct {int a; long long b;}));</div><div>return 0;</div><div>}</div><div><br></div><div>MODULE Main;</div><div>IMPORT IO, Fmt, Ctypes;</div><div><br></div><div><br></div><div>BEGIN</div><div>IO.Put(Fmt.Int(BYTESIZE(RECORD a:Ctypes.int; b:LONGINT; END)));</div><div>IO.Put("\n");</div><div>END Main.</div><div><br></div><div>import("m3core")</div><div>import("libm3")</div><div>implementation("Main")</div><div>build_standalone()</div><div>program("a")</div><div><br></div><div>jair:1 jay$ cc -m32 1.c</div><div>jair:1 jay$ ./a.out</div><div>12</div><div><br></div><div>jair:1 jay$  cm3 -DTARGET=I386_DARWIN  </div><div>--- building in I386_DARWIN ---</div><div><br></div><div>new source -> compiling Main.m3</div><div> -> linking a</div><div>jair:1 jay$ ./I386_DARWIN/a</div><div><br></div><div>16</div><div><br></div><div><br></div><div><br></div><div><br></div><div>Now, if you are going to use x86 interlocked instructions on this,</div><div>you might need higher alignment anyway. Might.</div><div><br></div><div><br></div><div><br></div><div>(Which all goes to my point -- while layout rules can't actually be removed,</div><div>they have to exist, it does behoove one to try to layout data that has</div><div>obvious portable layout, if you need interop. i.e. you just would not ever</div><div>have a record like this. You would make the likely padding explicit.</div><div>Or sort by size. Though once you put records within records, it becomes</div><div>difficult/impossible.)</div><div><br></div><div><br></div><div><br></div><div> - Jay</div><br>                                          </div></body>
</html>