Skip to content

JNAerator: Anonymous nested unions/structs are converted to nested classes with same name as enclosing class #132

@mvarnim

Description

@mvarnim

Issue description

A c union containing anonymous unions and structs is defined in a header file:

typedef union myUnion{
    double data[4];
    struct{
        union{
            struct{
                double vec[3];
                
            };
            struct{
                double i;
                double j;
                double k;
            };
        };
        double s;
    };
} myUnion;

This is converted to Java classes by JNAerator in the form:

public class myUnion extends Union {
	public double[] data = new double[4];
	public field1_struct field1;
	public static class field1_struct extends Structure {
		public field1_union field1;
		public double s;
		public static class field1_union extends Union {
			public field1_struct field1;
			public field2_struct field2;
			public static class field1_struct extends Structure {
				/** C type : double[3] */...

The inner class field1_struct, which represents the inner anonymous struct, has the same name as the enclosing class, which represents the outer anonymous struct. JNAerator generates these names automatically in the absence of struct names in the native code.

This leads to the Java error The nested type field1_struct cannot hide an enclosing type.

An interim solution is manual modification of the generated Java files after running JNAerator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions