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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:01:31+00:00 2026-05-24T13:01:31+00:00

I have a function in c that adds a row to a table. The

  • 0

I have a function in c that adds a row to a table. The function takes as arguments various orderings of ints, floats, and strings by using an ellipsis add_row(int arg1, int arg2, ...) and parses this information based on how the columns are set up.

I need to call this function from Java and am using JNI. I’m not sure what the best way to do this is especially with Java’s stricter typing. I’ve considered a few solutions but none of them seem any good / I’m not sure how to implement them: passing everything as strings, passing a jobjectArray, or passing cell values one at a time.

Any help is much appreciated.

Thanks,

Ben

  • 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-24T13:01:32+00:00Added an answer on May 24, 2026 at 1:01 pm

    This is less a problem with Java and JNI and more a problem of how to call a var args function in C with a dynamic list of arguments.
    See Calling a C function with a varargs argument dynamically which suggests having two versions of the var args function (although I think the convention is more to allow passthrough of an existing va_list, rather than for constructing one (which seems to be quite involved)).

    The JNI bit should be just to define a Java native method with object array arguments which will have a C equivalent receiving the array. Use the JNI API to convert the values into the C equivalents (ints and ANSI strings) then load them into the var args structure and call your vadd_row() function.

    Java:

    package mypackage;
    public class MyClass {
        ...
        public native void addRow(Object[] args);
        ...
    }
    

    C:

    void vadd_row(int arg1, int arg2, va_list argp) {
        ... your function ...
    }
    
    void add_row(int arg1, int arg2, ...) {
        va_list argp;
    
        va_start(argp, arg2);
        vadd_row(int arg1, int arg2, argp);
        va_end(argp);
    }
    
    
    JNIEXPORT void JNICALL mypackage_MyClass_addRow(JNIEnv *env, jobject this, jint arg1, jint arg2, jobjectArray jarg_array) {
        va_list argp;
        /* need to construct argp, see link below for hints[1]; go through each element
           of the java array, get the object; convert to primitive value or ANSI string,
           then encode it into the va_list */
        vadd_row((int)arg1, (int)arg2, argp);
    }
    

    [1] https://bbs.archlinux.org/viewtopic.php?pid=238721

    Is it worth the hassle?

    Consider just writing a simpler C function that receives the arguments in an array, then create a wrapper that uses var args if needed.

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

Sidebar

Related Questions

I have some JavaScript that creates a row in a table and adds cells
I have a function that adds eventhandlers to control events. Right now I have
I have such function, that adds a grid of droppables: function AddClassroomDrops(grid, weeks, days,
I have this function, that adds 31px to my style bottom on ul. It
I have a javascript function that manipulates the DOM when it is called (adds
I have a function that takes, amongst others, a parameter declared as int privateCount
I have a form that creates inputs in a table row. I have now
I have written a function that adds a ball to an array yet when
I have a function that adds a lot of numbers with decimals.... FLOAT numbers
I have a function that adds an entry to the database, the code 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.