Jump to content
Excelsior Forums
stephens

Passing data structure

Recommended Posts

Is it necessary to define all of the fields of a structure. There are some in a structure that will be passed to a callback that I don't care about. I know the length of the fields. Can just make them fixed length char arrays?

One of the fields is a possibly zero terminated. (Don't know yet, requirements issue)  :-/ If it is not zero terminated, is it still CSTRING?

How does a ushort map (Intel 386 arch)?

Share this post


Link to post
Share on other sites
Is it necessary to define all of the fields of a structure. There are some in a structure that will be passed to a callback that I don't care about. I know the length of the fields. Can just make them fixed length char arrays?

Yes, you can use char array, but the size of the array shall include the gap due to C alignment. For example, in C structure {char a; int b; short c}, if you want to change 'int b' to array of chars, then you must use char[7] instead of char[4].

One of the fields is a possibly zero terminated. (Don't know yet, requirements issue)   If it is not zero terminated, is it still CSTRING?

If the field is defined as "char*" in C structure, it is a String in Java, but it must be zero-terminated (otherwise there is no way for xFunction code to automatically determine its size). If it is 'char[..]', then it shall be represented as array of chars of the same size in Java.

How does a ushort map (Intel 386 arch)?

In structures one shall use 'short' Java type, as the size is required to be the same. To keep the whole ushort range one may write the trivial converter of the resulting Java short to int. In parameters of functions you may use 'int', as the size of parameters are always rounded up to 4.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×