8 messages in net.java.dev.jna.usersRe: [jna-users] Is there a way to han...
FromSent OnAttachments
Dennis PortelloMay 14, 2007 7:27 am 
Wayne MeissnerMay 14, 2007 5:59 pm 
Dennis PortelloMay 15, 2007 10:48 pm 
Wayne MeissnerMay 16, 2007 3:54 am 
Timothy WallMay 16, 2007 5:51 am 
Timothy WallAug 27, 2007 9:53 am 
Dennis PortelloAug 27, 2007 9:59 am 
Timothy WallAug 27, 2007 11:27 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] Is there a way to handle a union construct?Actions...
From:Timothy Wall (twa@users.sf.net)
Date:May 16, 2007 5:51:44 am
List:net.java.dev.jna.users

On May 16, 2007, at 6:55 AM, Wayne Meissner wrote:

Union class from it. My C is a bit rusty these days, so I'm looking for a nice challenge.

Unions are a bit tricky to implement properly in JNA. Although a Union class could be implemented, where it maps each of its members to the same memory area (basically the same as my example), there is no way for JNA to know which one of those members holds the most recently modified values that need to be written out to native memory.

A union is really nothing more than a shorthand for a cast, where something outside your client code is writing the memory and you don't know beforehand what's in it. Typically you have some flag (often the first field in the union) which tells you which union variant to use to extract the data, but using a union variant is no different than applying a typecast to the data pointer.

If you're just passing info to an API, then you should just define the data using the union variant you're using. There's no point in anonymizing the data.