Skip to content

Indexing a C array #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
certik opened this issue Jun 15, 2022 · 1 comment
Open

Indexing a C array #609

certik opened this issue Jun 15, 2022 · 1 comment

Comments

@certik
Copy link
Contributor

certik commented Jun 15, 2022

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.

@czgdp1807
Copy link
Collaborator

I will look into this later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants