Skip to content

Support C structs #606

Closed
Closed
@certik

Description

@certik

We want to be able to represent an equivalent of the following code in Python and generate the same C code using the C backend:

struct A {
    int32_t x;
    float y;
};

void f(struct A *a) {
    int32_t x = a->x;
    float y = a->y;
    ...
}

Here is one approach how the Python code could look like:

@dataclass
class A:
    x: i32
    y: f32

@ccallable
def f(a: CPtr) -> None:
    x: i32
    y: f32
    a2: Pointer[A]
    c_p_pointer(a, a2)
    x = a2.x
    y = a2.y

It looks like two prerequisites are needed before we can tackle this:

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