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 8245035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:03:36+00:00 2026-06-07T22:03:36+00:00

There is c struct definition struct Matrix { int width; int height; int** data;

  • 0

There is c struct definition

struct Matrix {
    int width;
    int height;
    int** data;
};

How to use python’s ctypes.Struct to define it?

class Matrix( ctypes.Structure ):
    _fields_ = [
        ( "width", ctypes.c_int ),
        ( "height", ctypes.c_int ),
        ( "data", ??? ),
    ]

I don’t know how to define the “data” ‘s type.
Anyone here help?

  • 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-07T22:03:37+00:00Added an answer on June 7, 2026 at 10:03 pm

    The most literal translation of int** would be:

    ctypes.POINTER(ctypes.POINTER(ctypes.c_int))
    

    That is, it is a pointer to a pointer to an int.

    A potentially more idiomatic way is a 2D array:

    ctypes.c_int * width * height
    

    , but to do that you need to know how many elements are in the array – the size is part of the type in ctypes. If, as it seems, you don’t know that size in advance (and it can change per instance of the struct), a pointer to a pointer is the best option.

    To instantiate this takes a little less indirection – by the time you want to create the array, by definition you will know how big it needs to be. So, you can just do:

    m.data = (ctypes.c_int * width * height)()
    

    Which will give you a height-length array of width-length arrays of c_int. That is, it does (broadly) the same thing as the C++ code:

    m.data = new int[width][height];
    

    Or, if you prefer:

    m.data = (int**) malloc(sizeof(int) * width * height)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in objc.h , there is definition for Class typedef struct objc_class *Class; typedef struct
There is struct like this. struct Address { int id; int set; char name[MAX_DATA];
Is a C# struct thread-safe? For example if there is a: struct Data {
There's a feature called anonymous class in C++. It's similar with anonymous struct in
There is a class definition and some bool functions which test some attributes class
There is a structure TA template <typename T> struct TA { typedef std::vector <T>
there. I have the foloowing class definition: [Serializable] public enum FilterType { [XmlEnum(1)] Text
My time.h has the following definition of tm : struct tm { int tm_sec;
I have a testing struct definition as follows: struct test{ int a, b, c;
Say I have the following class: template<class T> struct A { static int value;

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.