From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: To: 9fans@cse.psu.edu Subject: Re: [9fans] (no subject) From: Charles Forsyth Date: Tue, 14 Dec 2004 22:16:57 +0000 In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Topicbox-Message-UUID: 1602085e-eace-11e9-9e20-41e7f4b1d025 >>I am not sure the rationale was performance. sorry, i've confused things. i didn't mean that. i thought the rationale (seemed to be) that by using `packed', a programmer could describe an arbitrary protocol header (ok, the one for tcp/ip) using a precise sequence of C declarations within a structure and prevent the compiler from rearranging it to suit the given processor's natural alignment rules. that way the programmer could write simple C structure member accesses to access the elements of the header, rather than having to unpack explicitly. thus having `packed' makes the program both more readable and portable (except that non-gcc C compilers don't necessarily implement an analogue to `packed'). some fields will therefore be unaligned (on some processors). if, however, every unaligned access causes a trap to the kernel to repair, not only is it relying on every kernel resolving such traps, but more important, traps on most architectures are sufficiently expensive that .... it's horrendous! most compilers that are required to do it, compensate by generating code at the point of access that (somehow) does what is required.