| ▲ | C array types are weird(anselmschueler.com) | |||||||||||||||||||||||||||||||
| 38 points by signa11 2 days ago | 17 comments | ||||||||||||||||||||||||||||||||
| ▲ | uecker 2 days ago | parent | next [-] | |||||||||||||||||||||||||||||||
In practice, the [static n] notation can give you useful warnings and bounds checking. https://godbolt.org/z/PzcjW4zKK And while the (*array_ptr)[3] notation take a moment to get used to, it is very logical. If you have a pointer to an array, you dereference it first and then indx into it. Again, useful for bounds checking: https://godbolt.org/z/ao1so9KP7 | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | the__alchemist an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
This is one of the things that I feel is an inappropriate abstraction that is around for historical reasons. When I do FFI to call C from rust, I usually wrap the generated API (Which is pointer based) into rust's &[] array syntax. Arrays/lists/Vecs etc in most non-C languages feel like an abstraction over a collection of items; I feel like C's exposing the pointer directly is taking a low-level memory/MMIO operation and inserting it into business logic. Conceptually, I like to keep them separate; pointers for writing drivers, accessing registers, writing to flash memory etc. Arrays/lists/vecs for higher level operations on collections. Tangent: I have a pet theory that part of Zig's raison d'etre is to fix some of the problems with C, while accommodating its pointer-based data structures, and the resulting patterns. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | fatty_patty89 an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
there's no array type in c | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | IncreasePosts an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Paging walter bright | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | throwaway27448 22 minutes ago | parent | prev [-] | |||||||||||||||||||||||||||||||
Why are we still discussing c in 2026? Why are you intentionally hamstringing yourself unless you're using fucking hp-ux | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||