<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Yes, header too. And methods pointer is a structure from RT0 (methods and everything else). And data pointer program gets is address of first of fields.<br>
<br><div><div>On Mar 22, 2013, at 6:50 AM, Tony Hosking wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="content-type" content="text/html; charset=utf-8"><div dir="auto"><div>header</div><div>methods pointer</div><div>fields</div><div><br></div><div>If I recall correctly.<br><br>Sent from my iPad</div><div><br>On Mar 22, 2013, at 12:55 AM, Jay K <<a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a>> wrote:<br><br></div><blockquote type="cite"><div>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style>
<div dir="ltr">layout of objects?<br><br><br><br>How are Modula-3 objects layed out?<br>i.e. "OBJECT"/"METHODS"/"OVERRIDES"<br>I skimmed m3front and it wasn't obvious.<br><br><br><br>A common way for C++ "objects" to be layed out,<br>in the face of no RTTI and only single inheritance,<br>and virtual functions, is that a pointer to a record<br>of function pointers is first in the record.<br><br><br>Like this:<br><br><br>class Type<br>{<br>virtual void F1();<br>virtual void F2();<br>int data1;<br>int data2;<br>};<br><br><br>ends up lik more this:<br><br><br>struct TypeFunctions<br>{<br> void (*F1)(Type*);<br> void (*F2)(Type*);<br>};<br><br><br>struct Type<br>{<br>TypeFunctions* Functions; /* always first,<br>or at least a fixed offset, and located independent<br>of the size of the data; could also be at "-1" or such */.<br>int data1;<br>int data2;<br>};<br><br><br>Type* x;<br>x->F1();<br><br><br>=><br>x->Functions->F1(x);<br><br><br>Functions added in more derived types go at the end.<br>Ditto for data.<br>In the absence of multiple-inheritance and RTTI, it is simple and predictable.<br>(RTTI makes only small modifications.)<br><br><br>Looking through m3front, it wasn't at all obvious if it works this way.<br><br><br>I would like to declare something in C (or possibly C++, but not likely),<br>such that I might actually recognize the various low level operations<br>and "uncompile" it back to a typeful/typesafe form, like the above C++<br>to C transform.<br><br><br><br>I can't likely uncompile to C++ with virtual functions,<br>because the actual layout in C++ is not guaranteed.<br><br><br><br>Granted, I am being lazy.<br>I should/could compile some small samples.<br>But I might not get the entire story that way.<br><br><br><br>Thanks,<br>- Jay<br><br> </div>
</div></blockquote></div></blockquote></div><br></body></html>