How ptr arithmitic works??? It doesn't make any sense....
rempas
rempas at tutanota.com
Tue Dec 6 06:29:54 UTC 2022
On Monday, 5 December 2022 at 18:01:47 UTC, ag0aep6g wrote:
>
> You can use bracket notation with pointers. You just need to
> move your closing parenthesis a bit.
>
> Assuming that `ptr` is a `void*`, these are all equivalent:
>
> ```d
> (cast(int*) ptr)[i] = whatever;
> *((cast(int*) ptr) + i) = whatever;
> *(cast(int*) (ptr + i * int.sizeof)) = whatever;
> ```
Oh, wow! That's sure interesting! Thanks a lot!
More information about the Digitalmars-d-learn
mailing list