From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,971aa11c293c3db1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-07-23 04:08:08 PST Path: archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!195.27.83.146.MISMATCH!news-FFM2.ecrc.net!news.iks-jena.de!lutz From: lutz@iks-jena.de (Lutz Donnerhacke) Newsgroups: comp.lang.ada Subject: Re: Ada The Best Language? Date: Mon, 23 Jul 2001 11:05:50 +0000 (UTC) Organization: IKS GmbH Jena Message-ID: References: <5be89e2f.0107170838.c71ad61@posting.google.com> <5be89e2f.0107180235.726d46a8@posting.google.com> <3B55B01A.DAC06D79@icn.siemens.de> <5be89e2f.0107181248.73298c57@posting.google.com> <9j949b$1ujp$1@norfair.nerim.net> <9j983r$20jq$1@norfair.nerim.net> <9j9bdh$22kn$1@norfair.nerim.net> <9j9j37$27qe$1@norfair.nerim.net> <9j9nie$2anj$1@norfair.nerim.net> NNTP-Posting-Host: taranis.iks-jena.de X-Trace: branwen.iks-jena.de 995886350 4846 217.17.192.37 (23 Jul 2001 11:05:50 GMT) X-Complaints-To: usenet@iks-jena.de NNTP-Posting-Date: Mon, 23 Jul 2001 11:05:50 +0000 (UTC) User-Agent: slrn/0.9.6.3 (Linux) Xref: archiver1.google.com comp.lang.ada:10457 Date: 2001-07-23T11:05:50+00:00 List-Id: * Bertrand Augereau wrote: >> What do you expect by reading the source code line? What does really >> happen? Why can this remain in production software for years? > >The semantics is that it is an unsigned like any other unsigned, except >its capacity is different. And I would do capacity checking before this >affectation, anyway. Almost all people I showed this line instantly respond, that it stores the number of remaining packets. A few seconds later some people came up with the question how to store this in an IP packet because there is not field for. So they noticed the error due their profund knowledge of the context. Nobody was irritated by unmatching typed (even the compiler ...) -------------------- t.c -------------------- #include int main(int argc, char**argv) { struct { unsigned int b : 1; unsigned int c : 1; unsigned int d : 12; } tt; tt.b = 4; tt.c = 1; tt.d = 105; return printf("%d, %d, %d.\n", tt.b, tt.c, tt.d); } -------------------- t.s -------------------- .LC0: .string "%d, %d, %d.\n" main: pushl %ebp movl %esp,%ebp andl $-2,%edx orl $2,%edx andl $-16381,%edx orl $420,%edx pushl $105 movl %edx,%eax shrl $1,%eax andl $1,%eax pushl %eax movl %edx,%eax andl $1,%eax pushl %eax pushl $.LC0 call printf movl %ebp,%esp popl %ebp ret ---------------- reorder t.s ---------------- pushl $105 ; last argument on the stack (trivial) ; andl $-2,%edx ; edx is unknown value (clear the lowest bit) orl $2,%edx ; set the second lowest bit andl $-16381,%edx ; mask F..FC003 => edx = ?.. ?000000 00000010 orl $420,%edx ; set some bits edx = ?.. ?000001 10100110 ; movl %edx,%eax ; edx = ?.. ?000001 10100110 shrl $1,%eax ; eax = ?....?00000 11010011 andl $1,%eax ; eax = 1 pushl %eax ; third argument on the stack ; movl %edx,%eax ; eax = ?...?000001 10100110 andl $1,%eax ; eax = 0 pushl %eax ; second argument on the stack ---------------- reorder t.s ---------------- Ok, the compiler is truly irritated. >> 'guess'. No more questions. > >That's a bit of a nasty reaction. You don't have to be this arrogant. >I myself don't use this type of code often, and I don't have any standard >right there. Sorry, it sound like 'I do not have a standard, I learned by trial and error.' >The closest thing to a ref manual I got here, MSDN, says that for aligning >on a int boundary, you have to specify a bitfield size of zero, so it must >imply that other bitfields are packed, which sounds logical. Definitly.