[Pyrex] declear opaque type

Greg Ewing greg at cosc.canterbury.ac.nz
Fri May 2 04:51:14 CEST 2003


"King C. Shu" <kingshu at myrealbox.com>:

> Many libraries use opaque data type which are hidden from
> the user. Can pyrex let people work on an opaque type? 

Yes. A declaration such as

  cdef struct Foo

or

  ctypedef struct Foo

will give you an opaque type (more correctly known as an
"incomplete" type in C).

Here's a real-life example:

----------------------------------------------------
cdef extern from "Xlib.h":

  ctypedef struct Display

  Display *XOpenDisplay(char* display_name)

def foo():
  cdef Display *d
  d = XOpenDisplay("spam:0.0")
----------------------------------------------------

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+




More information about the Pyrex mailing list