Skip to content

Indexing a C array #609

Open
Open
@certik

Description

@certik

We need to be able to generate the following code in the C backend:

void f(uint16_t *q) {                                                  
    for (size_t i = 0; i < 10; i++) {
        g(&q[i])
    }
}

How should the Python code look like?

One idea:

@ccall
def g(a: CPtr) -> None:
    pass

@ccallable
def f(q_void: CPtr) -> None:
    q: Pointer[i16[:]]
    c_p_pointer(q_void, q)
    for i in range(10):
        q2: CPtr
        p_c_pointer(pointer(q[i]), q2)
        g(q2)

In LPython we can support this, but in CPython it might not be possible, so maybe we need to change pointer(q[i]) to pointer_index(q, i) or something like that.

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