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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:49:19+00:00 2026-06-15T03:49:19+00:00

I have a C function that takes an array of structures as an argument,

  • 0

I have a C function that takes an array of structures as an argument, and I want to call this function from Java by way of SWIG, but the documentation seems quite murky on this subject and I can’t find any stackoverflow questions that directly address this case. Here is an example that is similar to what I want to do:

C header file:

typedef struct {
  int timeToPayment;
  double paymentAmount;
} Payment;
double presentValue(Payment *payments, int nPayments);

Java code snippet:

...
Class Payment {
  public int timeToPayment;
  public double paymentAmount;
};
...
Payment[] payments = new Payment[3];
payments[0].timeToPayment = 30;
payments[0].paymentAmount = 1.0;
payments[1].timeToPayment = 60;
payments[1].paymentAmount = 2.0;
payments[2].timeToPayment = 90;
payments[2].paymentAmount = 3.0;
double pv = CLIBRARY.presentValue(payments);
// also acceptable: double pv = CLIBRARY.presentValue(payments, payments.length);

How can this be accomplished?

EDIT: to provide additional information, SWIG is a requirement because it is already used to incorporate simpler interfaces into the same Java codebase and supporting more than one approach for solving this problem will not be acceptable. Also, the signature of the C functions can’t be changed and this example has been extremely simplified; the actual problem involves multiple C functions with signatures requiring arrays of structs (multiple arrays of different structs in some cases) and some of the structs are quite large, so I would really, really prefer not to have to break them up into equivalent arrays of primitive types.

  • 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-15T03:49:20+00:00Added an answer on June 15, 2026 at 3:49 am

    In the end, I was unable to make this work (although I’m not saying that it isn’t possible to do), and I created a translation layer in C that wraps everything into a single struct before passing it through.

    • 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 takes a string-like argument. I want to decide if
I have a function that takes a variable and an associative array, but I
I have a function that takes an array of objects and I need to
I have a function that takes a const D3DVECTOR3 *pos , but I have
I have a function that takes variadic arguments, that I obtain from func_get_args() .
I have this function that takes the input of a, runs a calculation and
I have a function that takes the exact same args, but sometimes I'd like
I would like to have a function that takes an array as input and
I have a function that takes an array and creates a SQL statement based
I have a function in C++ that takes a char array thingArray[6] and places

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.