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

  • SEARCH
  • Home
  • 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 8195089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:01:00+00:00 2026-06-07T05:01:00+00:00

I have structure in Python code and in C code. I fill these fields

  • 0

I have structure in Python code and in C code. I fill these fields

("bones_pos_vect",((c_float*4)*30)),
("bones_rot_quat",((c_float*4)*30))

in python code with the right values, but when I request them in C code, I get only 0.0 from all array cells. Why do I lose the values? All other fields of my structures work fine.

class SceneObject(Structure):
    _fields_ = [("x_coord", c_float),
                ("y_coord", c_float),
                ("z_coord", c_float),
                ("x_angle", c_float),
                ("y_angle", c_float),
                ("z_angle", c_float),
                ("indexes_count", c_int),
                ("vertices_buffer", c_uint),
                ("indexes_buffer", c_uint),
                ("texture_buffer", c_uint),
                ("bones_pos_vect",((c_float*4)*30)),
                ("bones_rot_quat",((c_float*4)*30))]

typedef struct
{
    float x_coord;
    float y_coord;
    float z_coord;
    float x_angle;
    float y_angle;
    float z_angle;
    int indexes_count;
    unsigned int vertices_buffer;
    unsigned int indexes_buffer;
    unsigned int texture_buffer;
    float bones_pos_vect[30][4];
    float bones_rot_quat[30][4];    
} SceneObject;
  • 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-07T05:01:02+00:00Added an answer on June 7, 2026 at 5:01 am

    Here’s an example of how you can use a multidimensional array with Python and ctypes.

    I wrote the following C code, and used gcc in MinGW to compile this to slib.dll:

    #include <stdio.h>
    
    typedef struct TestStruct {
        int     a;
        float   array[30][4];
    } TestStruct;
    
    extern void print_struct(TestStruct *ts) {
        int i,j;
        for (j = 0; j < 30; ++j) {
            for (i = 0; i < 4; ++i) {
                printf("%g ", ts->array[j][i]);
            }
            printf("\n");
        }
    }
    

    Note that the struct contains a ‘two-dimensional’ array.

    I then wrote the following Python script:

    from ctypes import *
    
    class TestStruct(Structure):
        _fields_ = [("a", c_int),
                    ("array", (c_float * 4) * 30)]
    
    slib = CDLL("slib.dll")
    slib.print_struct.argtypes = [POINTER(TestStruct)]
    slib.print_struct.restype = None
    
    t = TestStruct()
    
    for i in range(30):
        for j in range(4):
            t.array[i][j] = i + 0.1*j
    
    slib.print_struct(byref(t))
    

    When I ran the Python script, it called the C function, which printed out the contents of the multidimensional array:

    C:\>slib.py
    0.1 0.2 0.3 0.4
    1.1 1.2 1.3 1.4
    2.1 2.2 2.3 2.4
    3.1 3.2 3.3 3.4
    4.1 4.2 4.3 4.4
    5.1 5.2 5.3 5.4
    ... rest of output omitted
    

    I’ve used Python 2, whereas the tags on your question indicate that you’re using Python 3. However, I don’t believe this should make a difference.

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

Sidebar

Related Questions

I have a python project with this directory structure and these files: /home/project_root |---__init__.py
I have this python code that will traverse a tree structure. I am trying
So I have Python code which creates a Linux TAP interface, but it always
The typical Python threadpool will have a structure like this one: def run(self): while
I have a python data-structure as follows: A = [{'abc': 'kjkjl'},{'abc': 'hjhjh'},{'abc': '78787'}] How
I have a nested Python data structure with datetime.datetime objects and namedtuples along the
In a Python system for which I develop, we usually have this module structure.
I have a Python project with following directory structure: /(some files) /model/(python files) /tools/(more
I have a Python project that has the following structure: package1 class.py class2.py ...
I have python code that contains the following code. d = {} d[(0,0)] =

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.