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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:23:29+00:00 2026-05-25T20:23:29+00:00

I have a function that accepts a double array as first parameter cb_type =

  • 0

I have a function that accepts a double array as first parameter

cb_type = CFUNCTYPE(c_void_p, c_double * 2, c_int, c_int)
def mycb(cube, ndim, nparams):
    print "cube before", [v for v in cube]
    for i in range(ndim):
        cube[i] = cube[i] * 10 * math.pi
    print "cube after", [v for v in cube]

I hand it over to C via the usual cb_type(mycb).

C calls it:

printf("values before: %f, %f\n", Cube[0], Cube[1]);
cb(Cube, *ndim, *npars);
printf("values after : %f, %f\n", Cube[0], Cube[1]);

When I run the program, there is some packing/unpacking or decoding issue:

values before: 0.047098, 0.010474           | C
cube before [4.3191267336e-314, 1e-323]     | Python, should be the same values
cube after [1.35689368162e-312, 3.1e-322]   | Python
values after : 0.047098, 0.010474           | C

How can I fix the encoding issue (receive [0.047098, 0.010474] in the python function)?

  • 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-05-25T20:23:29+00:00Added an answer on May 25, 2026 at 8:23 pm

    I fixed it by using POINTER(c_double) instead of c_double * 2.

    The new output looks like this:

    values before: 0.905349, 0.270400
    cube before [0.905348643442958, 0.2703996141057701]
    cube after [28.44236647177882, 8.494854412082024]
    values after : 28.442366, 8.494854
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that accepts wildcard keyword parameters: def func(**kargs): doA doB How
I have a function that accepts a generic parameter T that is of type
Please suppose I have a function that accepts a pointer as a parameter. This
I have a function that accepts one parameter and returns a table/resultset. I want
I have a function in C that accepts and returns a double (and uses
I have a function that accepts a variable length array of 80 character strings.
I have a function that accepts a large array of x,y pairs as an
I have a function that accepts an anonymous function as an argument and sets
I have a function that accepts a char* as one of its parameters. I
I have a function that accepts a class (not an instance) and, depending on

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.