This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author meador.inge
Recipients Pavel.Boldin, meador.inge
Date 2011-09-11.02:59:21
SpamBayes Score 1.6341472e-06
Marked as misclassified No
Message-id <1315709962.11.0.107021310865.issue12945@psf.upfronthosting.co.za>
In-reply-to
Content
Yes I can.  This seems strange, but it is correct.  The little endian case look like:

 Little endian
 ---------------------------------------
 | unsigned short   | unsigned short   |
 ---------------------------------------
 | bbbbaaaa ....cccc dddddddd ....dddd |
 ---------------------------------------
 | 00010010 00110100 01010110 01111000 |
 ---------------------------------------

where the 'd' bits pack from left to right, so '1000 01010110'.
The big endian case look like:

 Big endian
 ---------------------------------------
 | unsigned short   | unsigned short   |
 ---------------------------------------
 | aaaabbbb cccc.... dddddddd dddd.... |
 ---------------------------------------
 | 00010010 00110100 01010110 01111000 |
 ---------------------------------------

where the 'd' bits pack from right to left, so '01010110 0111'.

The native case (Structure) can typically be verified using your host C compiler.  For example, the above code can be represented in C as:

#include <stdio.h>

struct T
{
  unsigned char  a : 4;
  unsigned char  b : 4;
  unsigned short c : 4;
  unsigned short d : 12;
};

int main (int argc, char **argv)
{
  unsigned char bytes[] = {0x12, 0x34, 0x56, 0x78};
  struct T *t = (struct T*)&bytes;

  printf ("%X\n", t->a);
  printf ("%X\n", t->b);
  printf ("%X\n", t->c);
  printf ("%X\n", t->d);
}

With respect to structure layout, ctypes typically behaves the same way as the native compiler used to build the interpreter.
History
Date User Action Args
2011-09-11 02:59:22meador.ingesetrecipients: + meador.inge, Pavel.Boldin
2011-09-11 02:59:22meador.ingesetmessageid: <1315709962.11.0.107021310865.issue12945@psf.upfronthosting.co.za>
2011-09-11 02:59:21meador.ingelinkissue12945 messages
2011-09-11 02:59:21meador.ingecreate