Re: ctypes structure with a variable-size field at the end

gatch breizh <[email protected]>
Newsgroups gmane.comp.python.ctypes
Message-ID <[email protected]>
Thanks Mads for your quick response.
I will study your point.

.:Gatch

2010/6/15 Mads Kiilerich <[email protected]>

> gatch breizh wrote, On 06/15/2010 11:12 AM:
>
>  Hi,
>>
>> I would like to know how to write a ctypes::Structure with a variable-size
>> field at the end.
>> It occurs in many protocols to have a data field with a size early
>> defined.
>> I have been searching a solution through the web (very usual question) for
>> a while but without any success ...
>>
>>
> It might be possible to do with some clever tricks, but I would say:
>
> C don't have variable-size fields, but it allows you to work with such
> "fields" through careful pointer manipulations and careful reading within
> the bounds. I would use the same approach with ctypes. For example by
> finding the address where the field starts and cast it to a c_char*length
> array.
>
> /Mads
>

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo

_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.