RE: JNI in Java 1.6

  • From: "Ken Perry" <whistler@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 4 Jan 2011 12:58:07 -0500


The following shows how. Note the "...." operator in the function
definition.


/************************************************************************
 *
 * Purpose: Program to demonstrate functions that have a variable
 *          number of parameters.
 * Author:  M J Leslie.
 * Date:    28-Mar-94
 *
 ************************************************************************/

#include <stdio.h>
#include <stdarg.h>                     /* va_list, va_arg, va_end      */

int set(char *item, int num, ...);      /* Declare the function.        */

/************************************************************************/

main()
{
    char *item="pear";

    int   Ret;
     
    Ret = set (item,4, "apple", "pear", "banana", "grape");
     
    if (Ret)
    {
        printf ("%s found\n", item);
    }
    else
    {
        printf("%s not found\n", item);
    }
}

/************************************************************************/

int set(char *item, int num, ...)
{
    va_list ap;                         /* define 'ap' It acts as a
                                         * pointer to the undefined 
                                         * variables.                   */
    int Ret=0;
    int Inc=0;                          /* Assume the worst.            */
    va_start(ap, num);                  /* seed 'ap'                    */

    do
    {
        if ( item == va_arg(ap, char *))
        {
            Ret = 1;
        }
    } while ( Ret==0 && ++Inc < num);

    va_end(ap);                         /* tidy up.                     */
    return (Ret);
}

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Andreas Stefik
Sent: Tuesday, January 04, 2011 11:41 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: JNI in Java 1.6

If it is possible to do that in C, I have never done so. When I want
such behavior, I usually pass an array/vector/list instead.

Stefik

On Sat, Jan 1, 2011 at 10:01 AM, John J. Boyer
<john.boyer@xxxxxxxxxxxxxxxxx> wrote:
> Thanks. I found a way to generate the curly braces for functions using
> find and replace. Is there a way to refer to the parameters of a C
> function by position in the argumennt list rather than giving them
> names?
>
> Thanks,
> John
>
> On Sat, Jan 01, 2011 at 09:36:11AM -0600, Andreas Stefik wrote:
>> Hi John,
>>
>> QuentinC is correct. I would add one more thing, in that JNI has been
>> in the JDK for a very long time, and to my knowledge there should not
>> be any significant difference (if any) between 1.5 and 1.6 in relation
>> to it.
>>
>> My team, for example, has used a ton of JNI code both on 1.5 platforms
>> and 1.6, with no changes.
>>
>> Stefik
>>
>> On Sat, Jan 1, 2011 at 4:20 AM, QuentinC <quentinc@xxxxxxxxxxx> wrote:
>> > Hello,
>> > Try javah with only the full class name. It should generate an header
called
>> > something like java_package_subpackage_classname.h.
>> > Note, I would rather advise JNA for most projects, except if the
binding has
>> > to be very quick. IN JNA you don't have to write any C/C++ binding
code, the
>> > DLL is directly loaded.
>> >
>> >
>> > __________
>> > View the list's information and change your settings at
>> > //www.freelists.org/list/programmingblind
>> >
>> >
>> __________
>> View the list's information and change your settings at
>> //www.freelists.org/list/programmingblind
>
> --
> John J. Boyer; President, Chief Software Developer
> Abilitiessoft, Inc.
> http://www.abilitiessoft.com
> Madison, Wisconsin USA
> Developing software for people with disabilities
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
>
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: