<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'>I don't doubt that Modula-3 can handle it.<BR>
And I don't doubt that C can handle it.<BR>
But in both cases I find 1) the details beyond my attention span 2) definitely in the C case and very possibly in the Modula-3 case, not portable. You could learn the rules on one platform/compiler, only to produce code that doesn't work on others. Why bother learning them therefore? If you just want efficient storage in memory and don't care about the layout, then bitfields are ok. If you need to control the layout to interoperate with another system..even though bitfields are supposedly designed for this..I'm not sure I'd bother.<BR>
<BR>
<BR>
C bitfields don't have portable layout.<BR>
Do you suppose that Modula-3 ones do?<BR>
Maybe there are in fact an obvious set of rules that all compilers follow? I don't know.<BR>
<BR>
<BR>
Arrays of bytes have predictable layout.<BR>
Look at how binutils reads/writes object files. It does like this:<BR>
<BR>
<BR>
typedef struct elf_header_packed {<BR>
char signature[4];<BR>
char architecture[4];<BR>
char offset_to_foo[4];<BR>
} elf_header_packed;<BR>
<BR>
typedef struct elf_header {<BR>
long signature;<BR>
long architecture;<BR>
long offset_to_foo;<BR>
} elf_header;<BR>
<BR>
<BR>
and uses some pack/unpack functions to convert.<BR>
<BR>
<BR>
They are solving a slightly different problem.<BR>
They don't have bitfields necessarily to contend with, but just packing/size of integers that have a number of bits that are power of 2 (8, 16, 32, 64). <BR>
<BR>
<BR>
- Jay<BR> <BR>
<DIV>
<DIV id=SkyDrivePlaceholder></DIV>
<HR id=stopSpelling>
From: dragisha@m3w.org<BR>Date: Thu, 23 Aug 2012 21:59:46 +0200<BR>To: mika@async.caltech.edu<BR>CC: m3devel@elegosoft.com<BR>Subject: Re: [M3devel] I know, I know...<BR><BR>I have RTInfo module we developed years ago to parse .M3WEB. Good enough? :) But, not a solution, it is easier to write as I wrote in example I used to illustrate problem.
<DIV>
<DIV><BR></DIV>
<DIV>GCC not obeying packing instructions is like. GCC not working in lot of cases. For some reason, I don't believe in it.</DIV>
<DIV><BR></DIV>
<DIV>Hint, gm2 is GCC based compiler. And supports very precise packing/aligning rules.</DIV>
<DIV><BR>
<DIV><SPAN style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: medium Helvetica; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: medium Helvetica; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span>
<DIV style="WORD-WRAP: break-word">
<DIV>--</DIV>
<DIV>Divided by a common language</DIV>
<DIV><BR></DIV>
<DIV>Dragiša Durić</DIV>
<DIV><A href="mailto:dragisha@m3w.org">dragisha@m3w.org</A></DIV>
<DIV><BR></DIV></DIV></SPAN><BR class=ecxApple-interchange-newline></SPAN><BR class=ecxApple-interchange-newline></DIV><BR>
<DIV>
<DIV>On Aug 23, 2012, at 9:51 PM, Mika Nystrom wrote:</DIV><BR class=ecxApple-interchange-newline>
<BLOCKQUOTE>
<DIV><BR>Well I don't think Jay said that bytes couldn't be unpacked in Modula-3<BR>(you can just use Word for that).<BR><BR>But I think the point was that a compiler back-end might not necessarily<BR>obey your packing instructions?<BR><BR>Here's what I think you should do... it would be super useful, both to<BR>you and other people in the future. And completely independent of<BR>compilers.<BR><BR>Write a something-or-other that uses m3tk to read your RECORD type<BR>spec, plus pragmas of your own choice (or comments, or auxiliary data<BR>from somewhere) and then generates code using Word.T that can process<BR>byte streams and return the RECORD you declared, in portable Modula-3.<BR>I doubt it's very difficult. m3tk is cool!<BR><BR> Mika<BR><BR>=?utf-8?Q?Dragi=C5=A1a_Duri=C4=87?= writes:<BR>
<BLOCKQUOTE><BR></BLOCKQUOTE>
<BLOCKQUOTE>--Apple-Mail=_8871A9FB-3130-4B36-8524-F6549A5CEC9E<BR></BLOCKQUOTE>
<BLOCKQUOTE>Content-Type: multipart/alternative;<BR></BLOCKQUOTE>
<BLOCKQUOTE><SPAN style="WHITE-SPACE: pre" class=ecxApple-tab-span></SPAN>boundary="Apple-Mail=_2314A877-555E-4BDE-8112-C875A2AE5122"<BR></BLOCKQUOTE>
<BLOCKQUOTE><BR></BLOCKQUOTE>
<BLOCKQUOTE><BR></BLOCKQUOTE>
<BLOCKQUOTE>--Apple-Mail=_2314A877-555E-4BDE-8112-C875A2AE5122<BR></BLOCKQUOTE>
<BLOCKQUOTE>Content-Transfer-Encoding: quoted-printable<BR></BLOCKQUOTE>
<BLOCKQUOTE>Content-Type: text/plain;<BR></BLOCKQUOTE>
<BLOCKQUOTE><SPAN style="WHITE-SPACE: pre" class=ecxApple-tab-span></SPAN>charset=windows-1250<BR></BLOCKQUOTE>
<BLOCKQUOTE><BR></BLOCKQUOTE>
<BLOCKQUOTE>I have a friend, working for large software company and he just recently =<BR></BLOCKQUOTE>
<BLOCKQUOTE>ported some message router from SPARC to Linux/Intel=85 Lots of "network =<BR></BLOCKQUOTE>
<BLOCKQUOTE>order" data, same as with my current projects. Network, communication in =<BR></BLOCKQUOTE>
<BLOCKQUOTE>general, network order is everywhere.<BR></BLOCKQUOTE>
<BLOCKQUOTE><BR></BLOCKQUOTE>
<BLOCKQUOTE>Insisting on some god-given data ordering is a bit=85 What is nice word =<BR></BLOCKQUOTE>
<BLOCKQUOTE>here? :) Outlandish? Outimeish?<BR></BLOCKQUOTE>
<BLOCKQUOTE><BR></BLOCKQUOTE>
<BLOCKQUOTE>This is not first time I started discussion like this here. Every single =<BR></BLOCKQUOTE>
<BLOCKQUOTE>time Jay explains to me how Modula-3 cannot handle it. I am handling it, =<BR></BLOCKQUOTE>
<BLOCKQUOTE>as I have shown in my example, with Modula-3 code. With a bit of effort =<BR></BLOCKQUOTE>
<BLOCKQUOTE>I can make it almost-transparent (subfolder/platform) over various =<BR></BLOCKQUOTE>
<BLOCKQUOTE>platforms. Of course, as I am developing a full product (not software to =<BR></BLOCKQUOTE>
<BLOCKQUOTE>be run on arbitrary platform) I don't have to worry about too many =<BR></BLOCKQUOTE>
<BLOCKQUOTE>platforms. One is enough here, but I still think Modula-3 can benefit, =<BR></BLOCKQUOTE>
<BLOCKQUOTE>and a lot, if it supported explicit byte/bit ordering/packing/aligning =<BR></BLOCKQUOTE>
<BLOCKQUOTE>pragmas.<BR></BLOCKQUOTE>
<BLOCKQUOTE><BR></BLOCKQUOTE>
<BLOCKQUOTE>Also, unlike GCC, pointer alignment in Modula-3 is 64bit on x86_64. It =<BR></BLOCKQUOTE>
<BLOCKQUOTE>is 32bit in GCC, and x86_64 is totally happy with it. Wr have 64bit so =<BR></BLOCKQUOTE>
<BLOCKQUOTE>we must write piece of software in C to be what? Compatible with API's =<BR></BLOCKQUOTE>
<BLOCKQUOTE>all systems are compatible with without any hassle.=20<BR></BLOCKQUOTE>
<BLOCKQUOTE><BR></BLOCKQUOTE>
<BLOCKQUOTE>TIA<BR></BLOCKQUOTE>
<BLOCKQUOTE>--<BR></BLOCKQUOTE>
<BLOCKQUOTE>Divided by a common language<BR></BLOCKQUOTE>
<BLOCKQUOTE><BR></BLOCKQUOTE>
<BLOCKQUOTE>Dragi=9Aa Duri=E6<BR></BLOCKQUOTE>
<BLOCKQUOTE><A href="mailto:dragisha@m3w.org">dragisha@m3w.org</A><BR></BLOCKQUOTE>
<BLOCKQUOTE><BR></BLOCKQUOTE></DIV></BLOCKQUOTE></DIV><BR></DIV></DIV></DIV> </div></body>
</html>