Top Description Methods
org.graalvm.nativeimage.c.struct

public @Interface CStruct

extends Annotation
Annotations
@Retention:RUNTIME
@Target:TYPE
Imports
java.lang.annotation.ElementType, .Retention, .RetentionPolicy, .Target, org.graalvm.nativeimage.c.CContext, org.graalvm.word.PointerBase

Denotes Java interface that imports a C struct. The interface must extend PointerBase, i.e., it is a word type. There is never a Java class that implements the interface.

Field accesses are done via interface methods that are annotated with CField, CFieldAddress, or CFieldOffset. All calls of the interface methods are replaced with the appropriate memory or address arithmetic operations. Here is an example to define a complex number structure:

file="org/graalvm/nativeimage/StackValue.java" region="ComplexValue"
file="org/graalvm/nativeimage/StackValue.java" region="ComplexValue"
The annotated interface, or an outer class that contains the interface, must be annotated with CContext. Allocate an instances of the struct either by org.graalvm.nativeimage.StackValue#get(java.lang.Class) or by org.graalvm.nativeimage.UnmanagedMemory#malloc(org.graalvm.word.UnsignedWord). To access an array of structs one can define a special addressOf method:

file="org/graalvm/nativeimage/StackValue.java" region="IntOrDouble"
file="org/graalvm/nativeimage/StackValue.java" region="IntOrDouble"
Implementation of such method then allows one to do array arithmetics - e.g. obtain pointer to the first element of the array and then access the others:

file="org/graalvm/nativeimage/StackValue.java" region="acceptIntIntDouble"
file="org/graalvm/nativeimage/StackValue.java" region="acceptIntIntDouble"
Since
19.0
See Also
org.graalvm.nativeimage.StackValue, org.graalvm.nativeimage.UnmanagedMemory

Method Summary

Modifier and TypeMethod and Description
public boolean
addStructKeyword()

Add the C "struct" keyword to the name specified in value().

public boolean
isIncomplete()

If marked as incomplete, we will not try to determine the size of the struct.

public String
value()

Specifies the name of the imported C struct type.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

addStructKeywordback to summary
public boolean addStructKeyword()

Add the C "struct" keyword to the name specified in value().

Since
19.0
isIncompleteback to summary
public boolean isIncomplete()

If marked as incomplete, we will not try to determine the size of the struct.

Since
19.0
valueback to summary
public String value()

Specifies the name of the imported C struct type. If no name is provided, the type name is used as the struct name.

Since
19.0