portability problem with struct.{pack,unpack}

Stefano Zacchiroli zack at cs.unibo.it
Fri Aug 30 17:14:01 CEST 2002

Hi All,
  I'm writing an implementation of the talk protocol in (hopefully)
fully python, but I'm facing a portability problem regarding the
pack/unpack function from the structu module.

C's talk implementation use often type u_int_32 which is granted to be a
32 bit unsigned integer even on 64 bit architectures.  I have to send
over the network such kind of data (more preciselly struct that contain
such kind of data but, whatever ...).

I'm working on an intel architecture and all works fine if I use
pack("I", foo), which is the equivalente of an u_int_32 on my
The problem is that I suppose that python running on a 64 bit
architecture will pack "I" argument in a 64 bit unsigned int!

Seems to me that more kind of format are needed for the pack/unpack

I can solve the problem defining pack/unpack routines for my data in C
and rebuild them on each architecture, but I'm an obstinate guy and I
really want to complete the implementation in fully python!

Am I missing something?


Stefano Zacchiroli - undergraduate student of CS @ Univ. Bologna, Italy
zack at cs.unibo.it | ICQ# 33538863 | http://www.cs.unibo.it/~zacchiro
"I know you believe you understood what you think I said, but I am not
sure you realize that what you heard is not what I meant!" -- G.Romney

More information about the Python-list mailing list