I don't use floats and double much. But the printf man page implies that all floats are actually passed as doubles. I vaguely recall that to be the case.

But I doubt if the python thingy knows that. Try not passing floats. You might also have problems trying to pass char's and short's (since they are promoted
to int's).

On Dec 11, 2006, at 2:20 PM, Russell E. Owen wrote:

I've been trying out ctypes (from MacPython 2.5) on MacOS X on a PPC Mac and have run into a problem. I hope I'm just doing something stupid, but
it seems to match the tutorial so I'm really puzzled:

import ctypes
libc = ctypes.CDLL("libc.dylib")
libc.printf("int=%d float=%f double=%f\n", ctypes.c_int(1),
ctypes.c_float(2.0), ctypes.c_double(3.0));

results in:
int=1 float=-1.996124 double=0.000000

I realize the docs doesn't actually claim to handle dylib files, but
I've seen at least some info on the web that claims it works. One site
suggested the need for ctypes.RTLD_GLOBAL to CDLL but adding it made no
difference.

On a related subject...assuming I can get this to work...does anyone
have any idea how the speed of ctypes relates to programming a python C
extension or using SWIG? This is mostly for use with NumPy and
interfacing python to C/C++-based heavy duty astronomical image
processing code.

Other suggestions are welcome. We'll mostly be interfacing to C++ so
I've considered trying out Boost, but it hasn't had an update in years
which worries me. Robustness, ease of use and speed are all major
requirements. Linux and MacOS X are the main platforms.

-- Russell

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Perry Smith ( [EMAIL PROTECTED] )
Ease Software, Inc. ( http://www.easesoftware.com )

Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems


_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to