# translate-c: enable pointer arithmetic with signed integer operand · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/291edafa1b3e6f56f88c3d1c542bdb25e99e45d1)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 291edafa1b3e6f56f88c3d1c542bdb25e99e45d1

Requested commit: 291edafa1b3e6f56f88c3d1c542bdb25e99e45d1

Commit: 291edafa1b3e6f56f88c3d1c542bdb25e99e45d1

Tree: 943031717a44342403e63b6b957fd04332edbbd7

Author: Evan Haas

Committer: Veikka Tuominen

## Message

```
translate-c: enable pointer arithmetic with signed integer operand

Given a pointer operand `ptr` and a signed integer operand `idx`

`ptr + idx` and `idx + ptr` -> ptr + @bitCast(usize, @intCast(isize, idx))
`ptr - idx` -> ptr - @bitCast(usize, @intCast(isize, idx))

Thanks @LemonBoy for pointing out that we can take advantage of wraparound
to dramatically simplify the code.

```

## Parents

- [02737d535ac5bda4e9a00ec0ae11ae313065dfbb](https://git.cafe/gitcafe/zig/commit/02737d535ac5bda4e9a00ec0ae11ae313065dfbb?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/291edafa1b3e6f56f88c3d1c542bdb25e99e45d1?format=markdown)
