isaric
isaric

Reputation: 305

What does const char*** mean and how does it translate from C to Java?

I am using JNA to write a Java interface for a C++ written DLL for control of a small device.

While translating data types I came across

const char*** someVariable

Can someone please explain to me what this means and how can it be recreated in Java?

I have read up on pointers and I am using the JNA documentation to map C++ types to Java but I cannot find a reference to a type with three asterisks at the end.

Should this be interpreted as a pointer to a String array?

Upvotes: 2

Views: 531

Answers (2)

technomage
technomage

Reputation: 10069

The most likely interpretation is that you are expected to pass in the address of a pointer, and on return, the pointer will be an array of C strings.

That's not the only possible interpretation, but probably the most likely one. This is especially true if the native signature also asks for a pointer to integer into which it will write the length of the returned array.

To use this from JNA:

PointerByReference pref = new PointerByReference();
IntegerByReference iref = new IntegerByReference();
nativeLib.call(pref, iref);
String[] strings = pref.getValue().getStringArray(0, iref.getValue());

If no length is specified, JNA will look for a NULL value marking the end of the string array.

Upvotes: 3

Gravity
Gravity

Reputation: 311

if you know the concept of pointers,

const char*** means it is a triple pointer, so you can think of it this way:

const char***--->const char**--->const char*--->const char

So yes it can be interpreted as a pointer to a string array, because a string array can be interpreted as a double pointer.

let's say a is an array of strings:

const char *a[15];

In this case **a would give you the first char of the first string in a.

you can declare:

const char ***b = &a;

in this case ***b would give you the first char of the first string in a.

Upvotes: 5

Related Questions