https://dlang.org/spec/arrays.html#dynamic-arrays
My suggestion for C to adopt fat pointers:
https://dlang.org/spec/arrays.html#dynamic-arrays
My suggestion for C to adopt fat pointers:
So are Rust's.
Possibly more interestingly, so are its trait objects, the trait object pointer is a (vtable, instance) rather than (instance*, length).
Also of note: that applies to "owned pointers" (`Box`) not just "references", despite the former looking very struct-like: https://play.rust-lang.org/?version=stable&mode=debug&editio...
In a way, C++ and Rust (and possibly D?) have pretty much an infinity of fat pointers as anything can be made to deref' to something else, and be more than one pointer wide (e.g. C++'s std::string and std::vector and Rust's String and Vec)
> Possibly more interestingly, so are its trait objects, the trait object pointer is a (vtable,
> instance) rather than (instance*, length).
The Go interfaces are the same. See https://research.swtch.com/interfaces.https://security.stackexchange.com/questions/155572/how-are-...
Not that I'm against fat pointers in C, I always thought that in hindsight not having a primitive "slice" type was a mistake. In particular using NUL-terminated strings instead of slices is both error-prone and makes implementing even basic string-splitting functions like strtok annoying or inefficient (you need to be able to mutate the source string to insert the NULs or you have to allocate memory and copy each component. If you had slices you could easily return a portion of the string without mutation or copy).
In this case you get another problem: how to free memory when there might be many slices pointing at it.
extern void foo(char a[..]);
differ from extern void foo(size_t dim, char a[dim]);
if they are meant to be binary compatible?But anyway, you can use D in BetterC mode and have bounds checked slices!
(Jonathan Blow: Ideas about a new programming language for games.) https://www.youtube.com/watch?v=TH9VCN6UkyQ&list=PLmV5I2fxai...
When a language owns the platform its quality comes second.