<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="DejaVu Sans">Instead of rewriting your code you might
consider wrapping it with the C-API. I prefer this approach (over
ctypes) for anything "low level".<br>
<br>
<a class="moz-txt-link-freetext" href="http://docs.python.org/c-api/">http://docs.python.org/c-api/</a><br>
<br>
</font>On 09/06/2010 10:06 PM, Kwan Lai Cheng wrote:
<blockquote cite="mid:A4870644717D4CB68E791152072BBA82@cs0403293"
type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<meta name="GENERATOR" content="MSHTML 8.00.6001.18939">
<style></style>
<div><font face="Arial" size="2">Hi,</font></div>
<div> </div>
<div><font face="Arial" size="2">I'm trying to rewrite a c program in
python & encountered several problems. I have some data structures
in my c program like below:</font></div>
<div> </div>
<div><font face="Arial" size="2">typedef struct</font></div>
<div><font face="Arial" size="2">{</font></div>
<div><font face="Arial" size="2"> unsigned short size;</font></div>
<div> </div>
<div><font face="Arial" size="2"> unsigned short reserved:8;</font></div>
<div><font face="Arial" size="2"> unsigned short var_a1:2;</font></div>
<div><font face="Arial" size="2"> unsigned short var_a2:2;</font></div>
<div><font face="Arial" size="2"> unsigned short var_a3:2;</font></div>
<div><font face="Arial" size="2"> unsigned short var_a4:2;</font></div>
<div> </div>
<div><font face="Arial" size="2"> unsigned int var_a5;</font></div>
<div><font face="Arial" size="2">}structa;</font></div>
<div> </div>
<div><font face="Arial" size="2"> </font><font face="Arial" size="2"><font
face="Arial" size="2">typedef struct</font></font></div>
<div>
<div><font face="Arial" size="2"><font face="Arial" size="2">{</font></font></div>
<div><font face="Arial" size="2"><font face="Arial" size="2">
unsigned short size;</font></font></div>
<div><font face="Arial" size="2"> </font></div>
<div><font face="Arial" size="2"><font face="Arial" size="2">
unsigned char reserved:4;</font></font></div>
<div><font face="Arial" size="2"><font face="Arial" size="2">
unsigned char var_b1:1;</font></font></div>
<div><font face="Arial" size="2"><font face="Arial" size="2">
unsigned char var_b2:1;</font></font></div>
<div><font face="Arial" size="2"><font face="Arial" size="2">
unsigned char var_b3:1;</font></font></div>
<div><font face="Arial" size="2"><font face="Arial" size="2">
unsigned char var_b4:1;</font></font></div>
<div><font face="Arial" size="2"> </font></div>
<div><font face="Arial" size="2"><font face="Arial" size="2"> structa
var_structa;</font></font></div>
<div><font face="Arial" size="2"><font face="Arial" size="2">}structb;</font></font></div>
<div><font face="Arial" size="2"> </font></div>
<div><font face="Arial" size="2">I tried to code the above in python
but only got this far:</font></div>
<div><font face="Arial" size="2"> </font></div>
<div><font face="Arial" size="2">class StructA(object):</font></div>
<div><font face="Arial" size="2"> def __init__(self, size=0)</font></div>
<div><font face="Arial" size="2"> self.size = size</font></div>
<div><font face="Arial" size="2"> </font></div>
<div><font face="Arial" size="2">class StructB(object):</font></div>
<div><font face="Arial" size="2"> def __init__(self, size=0)</font></div>
<div><font face="Arial" size="2"> </font></div>
<div><font face="Arial" size="2">Any equivalent for c data structures
& bit fields in python? And how do I define var_structa (in
structb) in python?</font></div>
<div><font face="Arial" size="2"> </font></div>
<div><font face="Arial" size="2">Regards,</font></div>
<div><font face="Arial" size="2">Kwan.</font></div>
</div>
!SIG:4c85bc4844361237431282!
</blockquote>
</body>
</html>