11 messages in net.java.dev.jna.usersRe: [jna-users] Structure Order
FromSent OnAttachments
Nicolas VienneJan 10, 2008 2:15 am 
Albert StrasheimJan 10, 2008 2:32 am 
Nicolas VienneJan 10, 2008 2:56 am 
Albert StrasheimJan 10, 2008 3:02 am 
Albert StrasheimJan 10, 2008 3:08 am 
Timothy WallJan 12, 2008 10:49 am 
Nicolas VienneJan 17, 2008 3:45 am 
Albert StrasheimJan 17, 2008 3:48 am 
Timothy WallJan 17, 2008 5:15 am 
Nicolas VienneJan 17, 2008 5:53 am 
Nicolas VienneJan 17, 2008 5:56 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Structure OrderActions...
From:Timothy Wall (twal@dev.java.net)
Date:Jan 12, 2008 10:49:17 am
List:net.java.dev.jna.users

On Jan 10, 2008, at 5:15 AM, Nicolas Vienne wrote:

Hello everybody.

I have a little question about passing Structure between Java and Native : I noticed that the fields must be declared in the same order in both side.

Since C determines the memory layout based on the order of declaration, this is not exactly an onerous burden.

For example:

Java = public class TestStruct extends Structure { public int fieldA = 1; public int fieldB = 2; public int fieldC = 3; }

C++ = typedef struct TestStruct { int fieldA; int fieldB; // same ABC order in both sides int fieldC; } TestStruct;

Is there a way - other than avoiding structs - not to rely upon the field order ? I mean that I cannot know the order of both sides and thus it prevents me - for now - from using JNA.

I think you're leaving out some critical details about what you're trying to accomplish. Do you have some other high-level language which is auto-generating the struct layout? You will *always* need to tell the Java side how to map its struct fields into memory, whether it's by convention or explicit configuration.

If you can't know the order of the C side, there's no way you can access any given member of a C struct. On the Java side, you can always use a Structure solely as internal data and bind the fields in whatever manner you need to for the public API.