JNA passing the equivalent of swift pointer from Java Android to C

docker dev :

I am a little stuck trying to pass an implementation of this Swift code in Java, to C. Would appreciate any advice i am using JNA to integrate between the Java and Matlab generated C code.

This is the Swift call:

GetResult(uptime, &result_out)

It Maps to the C code:

void GetResult(double time, Result_t *Result)

The C struct Result_t is too big for here, however it is a combination of double's and int's.

I understand &result_out is a swift pointer? How is it best to go about implementing the equivalent of the Swift pointer in Java and then be able to pass it to C that is expecting a pointer to the Result_t which as i mentioned is a structure made up of doubles and ints.

Daniel Widdis :

The & denotes the memory address of a variable. In this case, it means the memory address of the Result structure.

In C you can see the * symbol used to denote the same thing: the variable to be passed as the second argument is the reference/memory address of the underlying data.

These often appear in pairs: if you have a variable foo defined you can easily pass &foo to any method expecting the pointer to foo, while the method itself uses the * notation to let you know it requires that pointer.

For many JNA structures you need to pay close attention to these symbols. Knowing whether to pass an int or IntByReference, for example, is key. But fortunately (for ease of writing code, or unfortunately for consistency) the behavior of the JNA Structure class is different. The bottom line is that, by default, when a Structure is included as an argument to a method/function (the most common application) the pointer, or ByReference version of the structure is used. So in this particular case, assuming you have mapped a class Result extends Structure with all the information, you can simply pass result where result = new Result();.

There are ways to use ByReference and ByValue to override this default behavior but that's beyond the scope of your question.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Passing pointer to pointer to float from Java through JNA to a C dynamic library

From Java

Passing pointer from java to native

From Dev

Swift equivalent of C++ Pointer / Reference convention?

From Java

Mac device access works in C, but equivalent code in Java/JNA not

From Dev

Passing a Swift protocol to an Objective-C pointer

From Dev

Pointer issues when mapping native C functions to Java interface with JNA

From Java

Equivalent of incrementing a C/C++ pointer in Java?

From Java

Use C++ DLL from Java with JNA

From Dev

Redirecting stdout from C lib in Java in JNA

From Dev

Passing pointer from C# to C++

From Dev

Equivalent objective C from Swift

From Dev

Passing pointer of a pointer in C

From Java

Passing a pointer from JNI to Java using a long

From Dev

Passing function pointer from native to java

From Java

JNA : Get value from a pointer to a pointer to a structure

From Java

JNA passing structure containing pointer to structure(s) and pointer to primitive

From

Passing pointer from go to c-dll

From Dev

Properly passing pointer from function C++

From Java

Pass pointer or PointerByReference in JNA for pointer argument in C

From Java

What is the difference between passing by reference in Java and passing a pointer in C?

From Java

Marshal.StructureToPtr Java equivalent in JNA

From Dev

Java equivalent from Obj C

From Java

Passing a Java class into a void* parameter with JNA

From Dev

How to pass a com.sun.jna.Structure from Java to struct in C, using JNA

From Dev

Is passing a DLL function argument with "const" an equivalent to pointer?

From Java

Equivalent on Objective C/Swift of Java ThreadLocal Variables

From Dev

What is equivalent of java ByteBuffer in Swift or Objective C?

From Java

JNA how to pass String[] from Java to C code

From Dev

Register callback from Java to C via JNI or JNA

Related Related

  1. 1

    Passing pointer to pointer to float from Java through JNA to a C dynamic library

  2. 2

    Passing pointer from java to native

  3. 3

    Swift equivalent of C++ Pointer / Reference convention?

  4. 4

    Mac device access works in C, but equivalent code in Java/JNA not

  5. 5

    Passing a Swift protocol to an Objective-C pointer

  6. 6

    Pointer issues when mapping native C functions to Java interface with JNA

  7. 7

    Equivalent of incrementing a C/C++ pointer in Java?

  8. 8

    Use C++ DLL from Java with JNA

  9. 9

    Redirecting stdout from C lib in Java in JNA

  10. 10

    Passing pointer from C# to C++

  11. 11

    Equivalent objective C from Swift

  12. 12

    Passing pointer of a pointer in C

  13. 13

    Passing a pointer from JNI to Java using a long

  14. 14

    Passing function pointer from native to java

  15. 15

    JNA : Get value from a pointer to a pointer to a structure

  16. 16

    JNA passing structure containing pointer to structure(s) and pointer to primitive

  17. 17

    Passing pointer from go to c-dll

  18. 18

    Properly passing pointer from function C++

  19. 19

    Pass pointer or PointerByReference in JNA for pointer argument in C

  20. 20

    What is the difference between passing by reference in Java and passing a pointer in C?

  21. 21

    Marshal.StructureToPtr Java equivalent in JNA

  22. 22

    Java equivalent from Obj C

  23. 23

    Passing a Java class into a void* parameter with JNA

  24. 24

    How to pass a com.sun.jna.Structure from Java to struct in C, using JNA

  25. 25

    Is passing a DLL function argument with "const" an equivalent to pointer?

  26. 26

    Equivalent on Objective C/Swift of Java ThreadLocal Variables

  27. 27

    What is equivalent of java ByteBuffer in Swift or Objective C?

  28. 28

    JNA how to pass String[] from Java to C code

  29. 29

    Register callback from Java to C via JNI or JNA

HotTag

Archive