How to intialise a C struct?

36 views
Skip to first unread message

NAVEEN

unread,
Jun 16, 2021, 3:59:27 PM6/16/21
to cython-users

I am trying to toy with some Windows API. I am trying to initialize a struct called  `WNDCLASS`.

I created a .pxd with

cdef extern from "windows.h":
    ctypedef struct WNDCLASS:
        ...

Now, how will I initialise `WNDCLASS` with all the attribute set as NULL? On C doing something like

WNDCLASS wc = {};

would do that trick. How to do that in Cython?


Casper van Elteren

unread,
Jun 28, 2021, 5:53:06 AM6/28/21
to cython-users

You initialize  a struct as such, where inside the brackets are the members of the struct (in order).

```
ctypedef struct some_struct:
    size_t x

cdef some_struct x = some_struct(1)

print(x.x)
```
Reply all
Reply to author
Forward
0 new messages