support of c++ alignas

26 views
Skip to first unread message

Nikhil Garg

unread,
Jun 26, 2019, 10:18:16 AM6/26/19
to cython-users
I am currently working on wrapping a c++ library. Within this library, there is a struct defined with c++ alignas keyword. I would like to know whether it is possible to specify that within cython.


template <typename T>
struct alignas(64) dataStruct {
uint32_t nx;
uint32_t ny;
}

I tried to translate it into cython, however, i am not sure what the syntax would be or should I just ignore putting alignas

cdef cppclass dataStruct:
 uint32_t nx
 uint32_t ny


I am not sure about the reasons for c++ to use alignas, but I need this struct to be present in cython wrapper, therefore, would like to know a possible way of mapping it.

Robert Bradshaw

unread,
Jun 26, 2019, 10:50:39 AM6/26/19
to cython...@googlegroups.com
You don't need to worry about declaring this in the Cython file; all
that's needed is the types and names of the members in the struct such
that Cython can generate the correct access code when it generates the
C file. (After Cython generates the C code, it is passed off to a
C[++] compiler that will read the actual header definitions and do the
right thing.)
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/955c8a21-0800-4848-97bd-7bcc4bc3469b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Nikhil Garg

unread,
Jun 27, 2019, 3:15:38 AM6/27/19
to cython-users
Thanks Robert.


On Thursday, 27 June 2019 00:50:39 UTC+10, Robert Bradshaw wrote:
You don't need to worry about declaring this in the Cython file; all
that's needed is the types and names of the members in the struct such
that Cython can generate the correct access code when it generates the
C file. (After Cython generates the C code, it is passed off to a
C[++] compiler that will read the actual header definitions and do the
right thing.)

On Wed, Jun 26, 2019 at 4:18 PM Nikhil Garg <nikhil...@gmail.com> wrote:
>
> I am currently working on wrapping a c++ library. Within this library, there is a struct defined with c++ alignas keyword. I would like to know whether it is possible to specify that within cython.
>
> https://en.cppreference.com/w/c/language/_Alignas
>
> template <typename T>
> struct alignas(64) dataStruct {
> uint32_t nx;
> uint32_t ny;
> }
>
> I tried to translate it into cython, however, i am not sure what the syntax would be or should I just ignore putting alignas
>
> cdef cppclass dataStruct:
>  uint32_t nx
>  uint32_t ny
>
>
> I am not sure about the reasons for c++ to use alignas, but I need this struct to be present in cython wrapper, therefore, would like to know a possible way of mapping it.
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cython...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages