<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'>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></body>
</html>