Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8539981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:29:42+00:00 2026-06-11T11:29:42+00:00

In Cython glue declarations, how do I represent a C struct type containing an

  • 0

In Cython glue declarations, how do I represent a C struct type containing an anonymous union? For example, if I have a C header file mystruct.h containing

struct mystruct
{
    union {
        double da;
        uint64_t ia;
    };
};

then, in the corresponding .pyd file

cdef extern from "mystruct.h":
    struct mystruct:
        # what goes here???

I tried this:

cdef extern from "mystruct.h":
    struct mystruct:
        union {double da; uint64_t ia;};

but that only gave me “Syntax error in C variable declaration” on the union line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:29:44+00:00Added an answer on June 11, 2026 at 11:29 am

    You can’t nest declarations to the best of my knowledge, and Cython doesn’t support anonymous unions AFAIK.

    Try the following:

    cdef union mystruct_union:
        double lower_d
        uint64_t lower
    
    cdef struct mystruct:
        mystruct_union un
    

    Now access the union members as un.lower_d and un.lower.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined and enum in cython header file api.pxd : ctypedef enum InstructionType:
I have this Cython class: cdef class Sprite: def __init__(self, someargument): pass And I
I have some C source code and want to wrap it in Cython. Now,
I have the newest XCode (4D199) installed and in terminal when I type new-host-2:
I am trying to compile a simple cython extension from the example page here
I have the following code that is to be propperly converted to cython: from
I have just managed to build my first C extension for Python, using Cython
I have a C++ class. It's made up of one .ccp file and one
In Cython, say I have a C function that returns a large buffer allocated
Is it possible to integrate Cython and TG2? I have one computation (written in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.