3 ms·
Good timing! I was having a conversation today with someone on a CUDA discord about it. The CUDA examples generally use `int` for the pointer size. I'd assumed
by the__alchemist 3y ago
Good timing! I was having a conversation today with someone on a CUDA discord about it. The CUDA examples generally use `int` for the pointer size. I'd assumed it was a shorthand for 32-bit-unsigned integer from the context, but it's apparently a standin that the compiler attempts to do the right thing with.
So, it's often used as you'd use `usize` in Rust, but not always! For now, my model is: use `int` where you would use `usize` in rust. It can also be used for other things, but it's better to use `uint32_t` or another explicitly-sized type.
- jcranmer 3y agoThat's a really bad idea. The C equivalent to `usize` is `uintptr_t` or `size_t` [1]. `int` is a 32-bit integer on all common platforms, while `long` is 32-bit on some 64-bit platforms and 64-bit on others. But on 64-bit platforms, `int` is not going to be large enough to store a pointer. [1] There's a subtle distinction between the two of them, but on most practical architectures you're coming across now, size_t == uintptr_t. This is actually a bit of a fight right now in Rust, since there's disagreement on what `usize` should do on systems where size_t != uintptr_t (the most common of which is CHERI).
- the__alchemist 3y agoThank you! Updating my code with this.