Writing C readable bitfield structs?
phark52 at yahoo.com
phark52 at yahoo.com
Thu Mar 17 16:01:09 EST 2005
Anyone have any idea?
phark52 at yahoo.com wrote:
> Roy Smith wrote:
> > In article <1111002678.866378.102970 at l41g2000cwc.googlegroups.com>,
> > Cappy2112 <cappy2112 at gmail.com> wrote:
> > >there is a bitfiled mainpulator class inthe Cookbook, but I don't
> > >understand his explanation, and the example given doesn't really
> show
> > >off the features of the class.
> >
> > I assume you're talking about the struct module? If you give an
> > example of the C struct you're trying to read/write, I could come
up
> > with some sample code to do it.
>
> struct S {
> unsigned int a : 1;
> unsigned int b : 1;
> unsigned int c : 1;
> unsigned int d : 1;
> };
>
> fread(from file (file written by Python app) into an instance of
struct
> S)
> then I want it to be used as follows:
> if (instance.a) f();
> if (instance.b) g();
> struct S comes out to 4 on my arch. I do not want to use a new int
for
> every member of struct S.
More information about the Python-list
mailing list