<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Apr 9, 2018 at 5:19 PM, Gert Wollny <span dir="ltr"><<a href="mailto:gw.fossdev@gmail.com" target="_blank">gw.fossdev@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Am Montag, den 09.04.2018, 14:03 -0400 schrieb Marek Olšák:<br>
> On Mon, Apr 9, 2018 at 10:51 AM, Bas Vermeulen <<a href="mailto:bas@daedalean.ai">bas@daedalean.ai</a>><br>
> wrote:<br>
</span>Which solution is better depends on what is done more often: reading<br>
the index or writing to the bit fields.<br>
<span class=""><br>
> > I am working on a new version of this patch. I have one version<br>
> > which does away with all the bitfields, and uses functions to<br>
> > update the index.<br>
</span>This emulates the code the compiler would create, but it requires that<br>
for each bit field setters (and getters?) must be implemented.<br>
<span class=""><br>
> > Another approach would be to change the union to a struct, and use<br>
> > a function to get the index.<br>
</span>This method has the advantage that only the access to the index needs<br>
new implementation.<br>
<span class=""><br>
> > Yet another approach would be to keep the contents of the union and<br>
> > the index in one struct, and use a function to<br>
> > (re)calculate the index.<br>
</span>I don't think that would make much sense.<br>
<br>
There is another option: Check at configuration time whether the bit<br>
field layout is like the low or the high endian layout you already<br>
implemented, and instead of basing the selection of the struct layout<br>
on the big/low-endianess of the architecture, base it on this test.<br>
<br>
It would probably be prudent to test both layouts and then fail<br>
configuration if non of the two reflect the actual layout (at which<br>
point one would have to thing about how to implement all the bit<br>
shifting properly).<br>
<span class=""><br>
> ><br>
> > Which would you prefer?<br>
> ><br>
><br>
> I don't mind bitfields. They make the code nice and tiny. Shifts<br>
> would decrease readability.<br>
</span>The problem is, that the layout of bitfields is compiler dependend.<br></blockquote><div><br></div><div>We can fix it after we discover that it's a real problem on a compiler we care about.<br></div></div><br></div><div class="gmail_extra">Marek<br></div></div>