I don't see a mistake here, certainly not a "biggest mistake". This is C, not C++. Keep it simple. Here, the idea is that there is no special type for "pointer+size" (what the author proposes as an array). Ok, let's add one and see the implications. - How do I get the size, the number of elements? A "sizeof" like operator? - Can I resize the array? If yes, how? If no, why? - What happens if I overflow? Undefined beha…
Here are it's answers:
- How do I get the size, the number of elements?
Builtin .len field operator. @sizeOf works too.
- Can I resize the array? If yes, how? If no, why?
No. Array lengths are comptime known; there is something called a slice which is runtime known and bounds checked in safe releases.
- What happens if I overflow? Undefined behavior?
Panic, in safe releases. UB in dangerous releases (small or fast)
- A memcpy-like would be an obvious function to implement, what happens if sizes differ?
Bounds checked at runtime for safe releases.
- What is the relationship between static arrays (ex: int a[5]) and "pointer+size" arrays? Are these completely different types? Is there an implicit cast between the two?
Yes, and yes. Arrays can implicitly be converted to slices at compile time; slicing into a slice with compile-time known index width yields an array.
- About casting, how can I go from a separate pointer and size to an array and vice versa? If it is possible at all.
There is an escape hatch function for this.
- What if I do a bit of pointer magic to access the internal representation of the array? Probably undefined behavior.
It's defined, but unsafe.
Do I haven't really worked too much in zig (it's not my daily driver) but I think it says something that all of these questions have answers to them, they are sensible, and very easy to remember.