Since your "bool" is of type char, the default mapping to "int" is not
correct. If you want to use boolean, you'll need to use a type mapper
to indicate boolean values should be converted to a byte as the native
representation.
Alternatively, you can just use a byte field in the structure.
In either case, the structure size will remain the same, due to
alignment and padding, but the value will be extracted from a single
byte at the given memory location, rather than from the last 4 bytes
of the structure (the last three of which will likely be random
garbage, which is why you're getting sporadic "true" values).
On May 27, 2009, at 9:56 AM, andry ivannikov wrote:
sizeof = 1
true = 1, false = 0;
On Wed, May 27, 2009 at 5:52 PM, Timothy Wall
<twal...@dev.java.net> wrote:
What is "bool" a typedef for? The default JNA mapping treats
boolean as "int", passing -1 for true and 0 for false.
If you can't find the bool typedef, you'll need to have your
compiler tell you sizeof(bool) as well as the values it's using for
true and false.
On May 27, 2009, at 9:34 AM, andry ivannikov wrote:
Struct in C:
struct Line
{
int symbols[ 5 ];
unsigned long result;
unsigned b1;
unsigned b3;
bool isAcc;
};
java mapping:
public class Line extends Structure {
public int[] symbols;
public NativeLong result;
public int b1;
public int b3;
boolean isAcc;
public WinLine() {
symbols= new int[(5)];
allocateMemory();
}
}
usage like this:
qqq(Line[] lines);
C librarary always set isAcc variable to false. Other fields return
correctly in java side. Last one, some times return true, some times
false.
Structure size is same (36) on C and JAVA size.
In documentation i'm not found C bool type mapping to java, i'm
suggested that it's boolean. However, java boolean map to C int type.
Where is my mistake?