<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'>Given:<br><br><br>struct foo<br>{<br>  union<br>  {<br>    struct<br>    {<br>      unsigned a : 16;<br>      unsigned b : 16;<br>    } s;<br>    unsigned c;<br>  } u;<br>} foo = { {1, 2} };<br><br><br>printf("%X %X\n", c.u.s.a, c.u.s.b);<br>What do people expect?<br>Do people really have a mental model as to what the layout rules are for bitfields?<br>Are they obvious enough that every C compiler writer has actually implemented them the same and they become in a sense portable? <br><br><br>Furthermore, if presented with:<br>struct foo<br>{<br>  unsigned a : 16;<br>  unsigned b : 16;<br>};<br><br>void F1(struct foo* f);<br>printf("%X %X\n", f->a, f->b);<br><br><br>Foo = RECORD a, b: BITS 16 FOR INTEGER END;<br><*EXTERNAL F1*> PROCEDURE F1(VAR foo: Foo);<br><br><br>VAR f := Foo{1,2};<br>F1(f);<br><br><br><br>What do people expect?<br><br><br>That is, 1) Does anyone really internalize the layout rules for bitfields?<br>2) Does anyone really need them to line up with C?<br><br><br>I ask because, it seems to me that in m3front/m3middle,<br>if Little_endian were removed and assumed either always<br>true or always false, everything would actually just work.<br><br><br>The only thing that would go wrong is<br>1) interoperability with C..when there are bitfields<br>2) including in m3core where floats are picked apart<br>2b) But that's kind of good -- we could remove the little vs. big endian distinction there.<br><br><br>See, I suspect but I am not certain the layout rules are actually well known to some small set of people, and they got encoded in m3front, in order for easier interoperability with C.<br><br><br>Repeat the above exercises for more complicated examples, i.e. bitcounts that aren't multiples of 16.<br><br><br> - Jay<br>                                        </div></body>
</html>