Oliver Neukum <[EMAIL PROTECTED]> writes: >> Unfortunately I can't have the correct type for this field in C (it >> should be "2-bytes-little-endian-unsigned-integer-unaligned"), so I >> can't get type-safety here anyway. Declaring this field __le16 is IMHO a >> poor attempt as it creates an illusion of type safety when in fact there >> is no type safety guaranteed. > > Then what tells you that char[8] is eight consecutive bytes in memory? > You'd use u8[].
If 'byte' is defined as minimal addressable unit, then it's C standard that guarantees char[8] is eight consecutive bytes in memory, I believe. Though it should better be 'unsigned char[8]'. If 'byte' is defined as '8bits', then there is no guarantee by the C standard that unsigned char is always 8 bits, but then there is probably no way to define either 'u8' or 'le16' on such an architecture, so neither of approaches being discussed would work, and one will need to resort, e.g., to the C bit-fields (that have their own set of problems). [I once had fun programming TMS320 that has 32-bits chars, so I did face those problems in practice, -- one just can't have anything shorter than 32 bits (but bit-fields) there, and serializing/deserializing something is a big pain] > If you do that, le16 is just as valid, especially if declared > unaligned. I don't think so: 1. 'unsigned char', be it used in the form of 'u8' or not, has neither alignment nor endianness problems, while le16 has both. 2. The only truth that le16 actually tells to the compiler is that this field is 2 bytes in size, and u8[2] tells that either. However, the u8[2] definition makes it hard to use this field as bare integer by mistake, so IMHO it wins from the POV of type-safety as well. [Besides, the name 'le16' could be confusing as it is bytes that are in little-endian order, and the type contains number of bits in its name, suggesting that all the 16 bits are in little-endian order ;)] -- Sergei. ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ linux-usb-devel@lists.sourceforge.net To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel