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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:17:49+00:00 2026-05-12T15:17:49+00:00

The SWIG documentation explains how a variety of input types in C, like this:

  • 0

The SWIG documentation explains how a variety of input types in C, like this:

void spam1(Foo *x);      // Pass by pointer
void spam2(Foo &x);      // Pass by reference
void spam3(Foo x);       // Pass by value
void spam4(Foo x[]);     // Array of objects

… would all take a single type of argument in Java, like this:

Foo f = new Foo();  // Create a Foo
example.spam1(f);   // Ok. Pointer
example.spam2(f);   // Ok. Reference
example.spam3(f);   // Ok. Value.
example.spam4(f);   // Ok. Array (1 element)

Similarly, for return types in C:

Foo *spam5();
Foo &spam6();
Foo  spam7();

… all three functions will return a pointer to some Foo object that will be assigned to a Java object variable, the final one requiring an allocation of a value type that the Java garbage collection will take care of upon release.

But suppose spam5() returns a pointer to an array. In Java, I have to use array semantics to access the individual elements, but I don’t think that I can just do this:

Foo foo[] = spam5();

I don’t even think the compiler would accept a cast to (Foo[]), so how does this work in SWIG?

  • 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-12T15:17:49+00:00Added an answer on May 12, 2026 at 3:17 pm

    This problem does not have a simple or automatic solution. Believe me, I looked.

    The problem is that SWIG doesn’t know how big the array you’re returning is supposed to be, so it can’t generate a Java array. You can’t supply the size as an argument to the function, either (gross as that would be) – typemaps don’t work that way.

    In the general case you have to write another wrapper function, which takes a C array and a length as an out parameter, and use a typemap to turn those two parameters into a Java array. Or, if you don’t mind using carrays.i, you can skip the second step and just work with C arrays directly from Java.

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

Sidebar

Related Questions

It seems that SWIG pointer-casting is broken : *(int **)&jresult = result; // shenanigans
I've gone over the SWIG FAQ and dynamic module documentation and there seems to
I would like to generate C wrappers over some C++ API using SWIG. From
First off: I'm new to both Qt and SWIG. Currently reading documentation for both
Per the SWIG Documentation (21.9.1 Default primitive type mappings), the C uint8_t is mapped
I have the following code wrapped by swig: int cluster::myController(controller*& _controller) { _controller =
I would like to use a .jar file generated by SWIG in an Android
I've something like this: typedef struct { char * content; } Boo; typedef struct
With prior OpenSSL versions it was possible to do this in SWIG .i files:
I'm learning SWIG, for using C in Python. I've written this function, but I

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.