[newbie] Which cast to go from *jint to *(unsigned long) ?

Discussion in 'C Programming' started by Barth?l?my von Haller, Nov 18, 2003.

  1. Hello!

    I'm trying to do a c library who will be called from a piece of java
    code (JNI). I have the following error when I compile this library :
    customJNI.c: In function
    `Java_com_xilinx_XHWIF_Boards_custom_customGetSystemInfo':
    customJNI.c:55: warning: passing arg 1 of `GetSystemInformation' from
    incompatible pointer type

    in customJNI.c:55:
    result = GetSystemInformation(body, length); // function in custom.c
    with jint *body; and jint length;

    and in custom.c :
    long GetSystemInformation(unsigned long *data, long length) {...}

    I understand that GetSystemInformation wait for a pointer unsigned
    long and that I give to it an *jint, but I don't know which cast I
    must use ?

    Thank you, regards

    Barthélémy von Haller
    Barth?l?my von Haller, Nov 18, 2003
    #1
    1. Advertising

  2. Barth?l?my von Haller

    xarax Guest

    "Barth?l?my von Haller" <> wrote in message
    news:...
    > Hello!
    >
    > I'm trying to do a c library who will be called from a piece of java
    > code (JNI). I have the following error when I compile this library :
    > customJNI.c: In function
    > `Java_com_xilinx_XHWIF_Boards_custom_customGetSystemInfo':
    > customJNI.c:55: warning: passing arg 1 of `GetSystemInformation' from
    > incompatible pointer type
    >
    > in customJNI.c:55:
    > result = GetSystemInformation(body, length); // function in custom.c
    > with jint *body; and jint length;
    >
    > and in custom.c :
    > long GetSystemInformation(unsigned long *data, long length) {...}
    >
    > I understand that GetSystemInformation wait for a pointer unsigned
    > long and that I give to it an *jint, but I don't know which cast I
    > must use ?
    >
    > Thank you, regards
    >
    > Barthélémy von Haller


    Just change your function to:

    result = GetSystemInformation((unsigned long*) body, (long) length);
    xarax, Nov 18, 2003
    #2
    1. Advertising

  3. Barth?l?my von Haller

    Dan Pop Guest

    In <R0qub.4750$> "xarax" <> writes:

    >"Barth?l?my von Haller" <> wrote in message
    >news:...
    >> Hello!
    >>
    >> I'm trying to do a c library who will be called from a piece of java
    >> code (JNI). I have the following error when I compile this library :
    >> customJNI.c: In function
    >> `Java_com_xilinx_XHWIF_Boards_custom_customGetSystemInfo':
    >> customJNI.c:55: warning: passing arg 1 of `GetSystemInformation' from
    >> incompatible pointer type
    >>
    >> in customJNI.c:55:
    >> result = GetSystemInformation(body, length); // function in custom.c
    >> with jint *body; and jint length;
    >>
    >> and in custom.c :
    >> long GetSystemInformation(unsigned long *data, long length) {...}
    >>
    >> I understand that GetSystemInformation wait for a pointer unsigned
    >> long and that I give to it an *jint, but I don't know which cast I
    >> must use ?

    >
    >Just change your function to:
    >
    >result = GetSystemInformation((unsigned long*) body, (long) length);


    This will shut up the compiler, but it doesn't mean that it is a
    particularly brilliant idea, especially if unsigned long and jint
    happen to have different sizes.

    The OP needs to understand why he is calling GetSystemInformation with
    a pointer to jint instead of calling it with a pointer to unsigned long,
    as the function expects and change either the caller or the callee so
    that they use the same type. The *last* thing you want to do is to
    cast a pointer so that the compiler no longer complains about your broken
    code.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, Nov 18, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Québec

    jni jint = int ?

    Québec, Jul 29, 2004, in forum: Java
    Replies:
    5
    Views:
    13,563
    Kevin McMurtrie
    Aug 3, 2004
  2. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    645
    Eric Sosman
    Jul 8, 2003
  3. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,162
    Peter Shaggy Haywood
    Sep 20, 2005
  4. TK
    Replies:
    3
    Views:
    421
  5. jeff

    cast unsigned long to long

    jeff, Dec 27, 2005, in forum: C Programming
    Replies:
    10
    Views:
    550
    Jack Klein
    Dec 27, 2005
Loading...

Share This Page