tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

re: Implement mode_select for atapi tape drives - round 4

   I don't get it. If the hardware (scsi devices in this case) defines
   a structure like e.g
   struct foo {
        int8_t data1;
        int32_t data2;
        int8_t data3
        int32_t data4;
   the software on the host side will have to do misaligned accesses whatever
   we do, isn't it ? How do we avoid the compiler from padding the members
   without __packed ?

by not abusing C structures for on-wire protocols.  for cases like
this, there's probably not much we can avoid.
   > Using structures to map hardware structures implicitly assumes knowledge
   > of the way compilers lay out structures - which may, or may not, be
   > guaranteed by the C standard.
   in such a case I don't think we can allow the compiler to decide how to
   lay out the structure.

this is correct.  depending on the compiler is not portable C.

the "right" way to do this is not never use "struct" but specific
length data and offsets.  that code tends to look uglier and be
harder to write.  hence why we abuse C.


Home | Main Index | Thread Index | Old Index